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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire