Laravel: how to add where clause using query builder? Laravel: how to add where clause using query builder? sql sql

Laravel: how to add where clause using query builder?


You may try something like this

$query =  DB::table('elements');$query->where('some_field', 'some_value');// Conditionally add another whereif($type) $query->where('type', 1);// Conditionally add another whereif($lang) $query->where('lang', 'EN');$rows = $query->get();

Also, check this answer.


$userId = Auth::id();$data['user_list'] =DB::table('users')->select('name')->where('id','!=',$userId)->where('is_admin','!=','1')->get();

like that you use multiple where clause :)