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?
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 .
$registrations = User::where(....)
->join('clients', 'clients.id', '=', 'user.id')
->get();
You could catch it by reading docs
$users = DB::table('users')
->leftJoin('clients', 'users.id', '=', 'clients.user_id')
->where('','')
->get();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.