Answer the question
In order to leave comments, you need to log in
Nested categories in Laravel?
Please tell me how to display nested categories correctly and in order not to load the database?
there is a category
table a category description table for each language
Category model
protected $table = 'categories';
protected $fillable = [
'image','parent','sort_order','published'
];
public function children()
{
return $this->hasMany(Category::class, 'parent');
}
public function description(){
return $this->hasMany(CategoryDescription::class, 'category_id');
}
protected $table = 'category_descriptions';
protected $fillable = [
'category_id','language_id','name','description','meta_title','meta_description','meta_keyword'
];
Answer the question
In order to leave comments, you need to log in
You have everything well organized. The only thing I highly recommend is https://github.com/GeneaLabs/laravel-model-caching. And so everything is fine with you.
in order not to load the database when sampling, use MPTT (Modified Preorder Tree Traversal)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question