Why does
Order::with(['products'=>function($q){
$q->select('name', 'price', 'quantity')->orderBy('name','asc');
}])->paginate($length);
returns all orders with their respective product data, but
Order::with(['products'=>function($q){
$q->select('name', 'price', 'quantity')->orderBy('name','asc');
}])->select('pickup_date', 'pickup_time', 'remark')->paginate($length);
gives me all order data I want, but an empty products array?
I want to select some specific columns from the order table with some specific columns from the products table. How can I do this?
FYI: Orders-products have a many-to-many relationship with models: Order Model:
public function products()
{
return $this->belongsToMany('App\Models\Product')->withTimestamps();
}
Product Model:
public function orders()
{
return $this->belongsToMany('App\Models\Order')->withTimestamps();
}
select('products.id as product_id', 'pickup_date', 'pickup_time', 'remark')- sta