Home > Article > PHP Framework > Introducing the advanced usage of where in Laravel
The following tutorial column will introduce to you the advanced usage of where in Laravel. I hope it will be helpful to friends in need!
in Laravel can use multiple wheres at the same time, so we can assign a where() to each fieldand then remove the closure in each where() Judgment$username = '';// 收货人姓名 $hospital_id = ''; // 医院id # 判断是否有姓名搜索 if (!empty($request->username)) { $username = $request->username; } # 判断是否有医院搜索 if (!empty($request->hospital_id)) { $hospital_id = $request->hospital_id; } # 执行 $data = DB::table('test') ->where(function($query)use($username){ # 进行判断 if (!empty($username)) { $query->where('username','Like',"%$username%"); } }) ->where(function($query)use($hospital_id){ # 进行判断 if (!empty($hospital_id)) { $query->where('hospital_id','=',$hospital_id); } }) ->get() ->toArray(); dd($data)
The above is the detailed content of Introducing the advanced usage of where in Laravel. For more information, please follow other related articles on the PHP Chinese website!