У меня есть две таблицы 1. пользователь 2. короткий список
Теперь я получаю данные о пользователях, в которых я также хочу, чтобы такие данные, как пользователь был включен в мой список или нет. Как я могу получить эти данные с помощью соединения.
общие поля: user.id == Shortlisted или user.id = ShortlistedBy
В настоящее время я получаю только пользовательские данные по этому запросу.
$users = DB::table('user')
->select('user.Name','user.Age','user.FatherGotra','user.Profession','user.City','user.State','user.AreYouManglik','user.DOB','user.ProfilePic','user.id')
->where('ShowProfileOnMatrimony','YES')
->where('Mobile','!=',$request->Mobile)
->where('isVerified',1)
->orderBy('user.id','DESC')
->paginate(5);
Пытаться:
$users = DB::table('user')->select('user.Name','user.Age','user.FatherGotra','user.Profession','user.City','user.State','user.AreYouManglik','user.DOB','user.ProfilePic','user.id','shortlist.isShortlisted as isshortlist')
->leftJoin('shortlist', 'user.id', 'Shortlisted')
->leftJoin('shortlist as ShortlistedBy', 'user.id', 'shortlist.ShortlistedBy')
->where('ShowProfileOnMatrimony','YES')
->where('Mobile','!=',$request->Mobile)
->where('isVerified',1)
->orderBy('user.id','DESC')
->paginate(5);
Больше информации здесь: https://laravel.com/docs/5.4/queries#joins
Других решений пока нет …