I have product model linked with discount and category;
$products = Product::with('discounts')->with('categories')->get();
I then manipulate products based on category
foreach ($products as $item) {
if (category_condition) {
$item['new_prod_attribute'] = 'data_cat';
}
if (discount_condition) {
$item['new_prod_attribute1'] = 'data_disc';
}
}
Now I want to get some selective data like: product->id,name,new_prod_attribute,new_prod_attribute1; category->name; discount->offer_name as subset_data;
You can use
mapWhen you dump
$productDatayou've all the data