PHP
laravel join with multiple conditions
$results = DB::table('rooms')
->distinct()
->leftJoin('bookings', function($join)
{
$join->on('rooms.id', '=', 'bookings.room_type_id');
$join->on('arrival','>=',DB::raw("'2012-05-01'"));
$join->on('arrival','<=',DB::raw("'2012-05-10'"));
$join->on('departure','>=',DB::raw("'2012-05-01'"));
$join->on('departure','<=',DB::raw("'2012-05-10'"));
})
->where('bookings.room_type_id', '=', NULL)
->get();
merge two query results in laravel
$teamStanding = Ladder::getTeamPosition($request->competitionId, $request->id)->get();
$teamStatistics = TeamCompetitionStatistics::getTeamStats($request->competitionId, $request->id)->get();
$merged = $teamStatistics->merge($teamStanding);
$result = $merged->all();
// return [{'teamstanding': 'data', 'teamstatictics': 'data'}]
join multiple tables in laravel eloquent
$users = User::join('posts', 'posts.user_id', '=', 'users.id')
->where('users.status', 'active')
->where('posts.status','active')
->get(['users.*', 'posts.descrption']);
laravel eloquent multiple join with where conditions
$users = User::join('posts', 'posts.user_id', '=', 'users.id')
->where('users.status', 'active')
->where('posts.status','active')
->get(['users.*', 'posts.descrption']);
laravel eloquent multiple join
$users = User::join('posts', 'posts.user_id', '=', 'users.id')
->join('comments', 'comments.post_id', '=', 'posts.id')
->get(['users.*', 'posts.descrption']);
laravel + join 2 eloquent queries
$select->joinSub(
$selectSubQry,
'ag',
'ag.id',
'=',
'agp.userId'
);