这期内容当中小编将会给大家带来有关怎么在Laravel中使用where方法,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
$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)
上述就是小编为大家分享的怎么在Laravel中使用where方法了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注天达云行业资讯频道。