Laravel中where怎样使用?Laravel中where的使用方法有很多,这篇主要给大家分享的是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的使用介绍,上述示例具有一定的借鉴价值,有需要的朋友可以参考学习,希望对大家学习where的使用有帮助,想要了解更多可以继续浏览群英网络其他相关的文章。
文本转载自脚本之家
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。