Answers for "laravel get nested relationships data with eager loading"

PHP
0

laravel get nested relationships data with eager loading

/*
|======================================================================================
| Get Category With Its Products and Product's First Variant -- Selected Columns Only
|======================================================================================
*/
$category_products = Category::select('id','title','banner_image')
                             ->where('id',$id)
                             ->with([
                                'products' => function($query) {
                                 	$query->select('id','name','primary_image','category_id');}, 
                                        'products.firstVariant' => function($query) {
                                               $query->select('id','retail_price','sale_price','product_id');
                                        }
                             ])
                             ->first();
Posted by: Guest on August-07-2021

Code answers related to "laravel get nested relationships data with eager loading"

Browse Popular Code Answers by Language