Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

Found this was answered on stack overflow,

http://stackoverflow.com/questions/27632236/laravel-eloquent-orwhere-query

for reference and searching,

Damien Pirsy:

You could do in three ways. Assume you've an array in the form

['myselect' => [11, 15, 17, 19], 'otherfield' => 'test', '_token' => 'jahduwlsbw91ihp'] which could be a dump of \Input::all();

       Project::where(function ($query) {
          foreach(\Input::get('myselect') as $select) {
             $query->orWhere('id', '=', $select);
          }
       })->get();

       Project::whereIn('id', \Input::get('myselect'))->get();

       $sql = \DB::table('projects');
       foreach (\Input::get('myselect') as $select) {
           $sql->orWhere('id', '=', $select);
       }
       $result = $sql->get();

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ravoras ravoras Joined 24 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.