Get all shipments and foreach shipment i need to count each products
I want to get all the shipments adding to each shipment each count of the scanned prods and the unscanned prods as shown here :
public function allShipments()
{
$ships = Shipment::all();
foreach ($ships as $ship) {
$scanned_products = $ship->products()->where('scanned', true)->where('visibility',true)->get();
$unscanned_products = $ship->products()->where('scanned', false)->where('visibility',true)->get();
$ship->$scanned_products = $scanned_products;
$ship->$unscanned_products = $unscanned_products;
}
return Datatables::of($ships)->make();
}
I want only the count of scanned and unscanned products foreach every ship , then using datatables with them which obligates not using all() or get as it only needs the query itself.
@MichalOravec Not really there are some conditionals that I need.
I see in the docs some conditionals BUT I am not able to generate the full query required for my case
{message: "The route [object%20Object] could not be found.",…}
exception
:
"Symfony\Component\HttpKernel\Exception\NotFoundHttpException"
file
:
/vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php"
line
:
44
message
:
"The route [object%20Object] could not be found."
trace
: