'bool', '_lft' => 'int', '_rgt' => 'int', 'parent_id' => 'int', 'serp_at' => 'datetime', ]; protected $fillable = [ 'name', 'short_name', 'slug', 'enabled', '_lft', '_rgt', 'parent_id', 'serp_at', ]; protected static function boot() { parent::boot(); static::saved(function ($category) { if (empty($category->slug)) { $category->slug = Str::slug($category->name); $category->saveQuietly(); } }); } public function saveQuietly(array $options = []) { return static::withoutEvents(function () use ($options) { return $this->save($options); }); } public function posts() { return $this->hasManyThrough( Post::class, PostCategory::class, 'category_id', // Foreign key on PostCategory table 'id', // Local key on Post table 'id', // Local key on Category table 'post_id' // Foreign key on PostCategory table ); } }