Laravel Eloquent orWhere Query

后端 未结 4 1556
悲哀的现实
悲哀的现实 2021-01-17 18:05

Can someone show me how to write this query in Eloquent?

SELECT * FROM `projects` WHERE `id`=\'17\' OR `id`=\'19\'

I am thinking

         


        
4条回答
  •  再見小時候
    2021-01-17 18:38

    In laravel 5 you could do it this way.

    $projects = Projects::query();
    
    foreach ($selects as $select) {
        $projects->orWhere('id', '=', $select);
    }
    
    $result = $projects->get();    
    

    This is very useful specially if you have custom methods on your Projects model and you need to query from variable. You cannot pass $selects inside the orWhere method.

提交回复
热议问题