lundi 30 novembre 2020

Laravel Eloquent - method to obtain grandchildren's data from GrandParents

I'm making Ecommerce-website and I have the following relationship:

Grandparents : Category ( id , name )
Parents : Brand ( id , name , category_id )
Children : Product ( id , name , brand_id )

Example : Smartphone (Category) -> iPhone (Brand) -> iPhone 12, iPhone 12 Pro, iPhone 12 Pro Max (Product)
I want to get all the iPhone 12 as above from Category likes

$iPhone = App\Category::find(1)->brands->where('name','iPhone')->toArray()

Thanks for helping



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/37ju02x
via IFTTT

Aucun commentaire:

Enregistrer un commentaire