mardi 26 janvier 2021

How to use multiple whereIn in laravel collection

I have a collection of arrays that I'm trying to return based on the $prices value that I passed in. $prices = ['100', '200'];

 $collection = collect([
   ['product' => 'Desk', 'price' => 100, 'price2' => 150],
   ['product' => 'Chair', 'price' => 150, 'price2' => 200],
   ['product' => 'Bookcase', 'price' => 300, 'price2' => 350],
   ['product' => 'Door', 'price' => 400, 'price2' => 200],
   ['product' => 'Door', 'price' => 450, 'price2' => 500],
 ]);

 $filtered = $collection->whereIn('price', $prices)->whereIn('price2', $prices);

 $filtered->all();

/* The result should return where price or price2 is 100 or 200:
  [
    ['product' => 'Desk', 'price' => 100, 'price2' => 150],
    ['product' => 'Chair', 'price' => 150, 'price2' => 200],
    ['product' => 'Door', 'price' => 400, 'price2' => 200],
  ]
*/


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/39lvCez
via IFTTT

2 commentaires:

  1. Quran tutor UK is providing online quran academy classes in UK and its main cities like Cambridge, Oxford, London and Bangor. We have best male and feminine staff. All teachers are highly qualified, well experienced. They are qualified from a reputable institute.

    Learn Quran Online

    RépondreSupprimer