lundi 30 janvier 2017

How to create dynamic query?

I have 7 records. 6 of them have selling and 1 is rent. In array i get this:

array:2 [▼
  0 => "Selling"
  1 => "Rent"
]

But when i foreach that in result i get 4 and not 7. Any suggestion how can i fix this. Im trying to create dynamic query so if i enter one more thing that i dont need to change here anything.

if(is_array($option)){
    foreach($option as $o){
        $q->orWhere('name', 'like', $o);
    }

  }
   else{
      $q->orWhere('name', 'like', $option);
   }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jKWaw1
via IFTTT

Aucun commentaire:

Enregistrer un commentaire