I'm using Laravel 5.8 to build my Online Store and in this Online Store there are two types of products. Physical products such as (books, magazines & etc) and Video type products.
Now I need to determine that if a user has added a Video type product and ALSO a Physical product to his Shopping Cart, a session called physical-video submitted.
And if the Cart ONLY contains Physical products, submit the session physical with value of 1 otherwise submit the value of 0 for it.
$product_videos = [];
$foundOrder = Cart::select('crt_content')->whereCrtId($cart->crt_id)->latest()->first();
$foundOrder = json_decode($foundOrder->crt_content);
foreach ($foundOrder as $key => $value) {
$product = Product::with('uploaded')->wherePrdId($value->id)->select('*')->first();
array_push($product_videos, $product->prd_video);
$prds[] = [
$product,
$value->quantity,
$value->price
];
$product_videos = array_unique($product_videos);
$pvWithoutNull=array_filter($product_videos,function($_v){return $_v !== null;}); //$product_videos without any null value
if(in_array(null, $product_videos)){
if(empty($pvWithoutNull))
Session::put('physical', 1); // only physical
else
Session::put('physical-video', 1); // physical-video
}else{
Session::put('physical', 0); // only video
}
}
But it does not work properly because if I add ONLY Physical products to the Cart, the session Session::put('physical', 1); does not submitted and otherwise Session::put('physical-video', 1); submitted wrongly.
And if I dd($pvWithoutNull), I get this result for only Physical products:
capture
So how can I check this submit physical session with value of 1 properly if only Physical products added to Cart?