[英]How to use leftJoin in Laravel for case?
I have the following code:我有以下代码:
$registrations = User::where(function ($query) use ($request) {
if (!is_null($request->region) && $request->region !== '0') {
$query->where('region', $request->region);
}
})->get();
How to join User
result with another model Clients
with Left Join
condition?如何将
User
结果与具有Left Join
条件的另一个模型Clients
Left Join
?
I tried this way:我试过这种方式:
$registrations = User->join('clients', 'clients.id', '=', 'user.id')->where(...
Read the documentation first: https://laravel.com/docs/5.5/queries#joins .首先阅读文档: https : //laravel.com/docs/5.5/queries#joins 。
$registrations = User::where(....)
->join('clients', 'clients.id', '=', 'user.id')
->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.