The task for me today was to filter the products as per their status i.e if they are published then their value would be 1 and if they are unpublished then their value would be 0. But I didn’t want to create three queries for them, one for each condition. Therefore, I used the if condition inside query like this.
But I didn’t have an answer to what to do to get all the products whatever their status maybe so I kept the else field empty.
The code is down below. I passed the $status variable which has either ‘published’ or ‘unpublished’ or ‘all’ condition.
return Product::where(function($query) use ($status) {
if($status == 'published') {
$query->where('product_status', 1);
}
elseif ($status == 'unpublished'){
$query->where('product_status', 0);
}
else {
}
})
->get();
I hope this helps you too.
I like this website very much so much wonderful info .
mexican border pharmacies shipping to usa
https://cmqpharma.com/# mexican border pharmacies shipping to usa
medicine in mexico pharmacies
Once you get on the cycle, it ll be better for you and the people priligy tablet