I am trying to write a query which takes a collection of records and loops through them and displays them all but i need it to hide a specific record if one record contains a field as true.
Use Case
- Grab collection of products where the
purchasedfield is true - if a product from the collection has the field
includes_bonusset to true list ALL products apart from thebonusproduct which has the id of 2
1.
This grabs all the products that have purchased set to true
$productsPurchased = $user->products()->where('purchased', 1)->get();
2 attempt
Below i trying to do the above but im not having much luck.
-
Grab all products with purchased set to 1(true)
-
if product
includes_bonusas 1(true) hide product record with id of 2 from list of products.$productsPurchased = $user->products()->where('purchased', 1) ->where('includes_bonus', 1) ->where('products.id', '!==', 2) ->get();
blade
I then wanna do a foreach within the blade which lists all the products with my use case.
@foreach($purchasedProducts as $purchasedProduct)
<div class="col-xl-6 p-0 p-xl-4 mb-5 mb-xl-0">
<div class="card border">
<div class="card-header border rounded-top"
</div>
<div class="card-block">
@endforeach
Aucun commentaire:
Enregistrer un commentaire