Edit
This question is unique because it poses unique problems such as:
- relations within the with components. (items.product.stockManagement).
- A large amount of components, this causes the accepted answers of the linked question to not apply.
Suppose you have a large with() like the following:
$order = Order::with([
'company',
'complaints',
'person',
'items',
'items.product',
'items.product.stockManagement',
'status',
])->findOrFail($id);
How can I then select with all their relations but specific columns for some of them?
$order = Order::with([
'company', // select only id,name, size
'complaints', // select only id, name , body
'person',
'items',
'items.product', // select only id, name , price
'items.product.stockManagement',
'status', // select only id
'items.product.media',
'items.product.mainProduct',
'items.product.mainProduct.media'
])->findOrFail($id);