Я хочу добавить дополнительный фильтр в мое левое соединение, но я не знаю, как любезно помочь мне. А также расскажите, как можно сделать этот запрос в Eloquent. Мой запрос приводится ниже:Входит в laravel 5.3 в простой и ярый
select * from `users`
join `halls` on `halls`.`user_id` = `users`.`id`
left join `bookings` on `bookings`.`hall_id` = `halls`.`id` AND month(`bookings`.`date`) = 2 and day(`bookings`.`date`) = 4 and year(`bookings`.`date`) = 2017
join `user_role` on `user_role`.`user_id` = `users`.`id`
join `roles` on `roles`.`id` = `user_role`.`role_id`
where
`roles`.`id` = 2 AND
(`bookings`.`id` is null OR `bookings`.`status` = 0)
group by users.id
пользователь и роль имеет многие ко многим отношения, пользователей и зал один ко многим и зала и заказов также имеет один ко многим отношения пользователя реляционная модель
/**
* Many-to-Many relations with Role.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles(){
return $this->belongsToMany(Role::class, 'user_role', 'user_id', 'role_id')->select('roles.name');
}
/**
* One-to-Many relations with halls.
*
* @return \Illuminate\Database\Eloquent\Relations\hasMany
*/
public function halls(){
return $this->hasMany(Hall::class);
}
Hall отношение Модель
public function user(){
return $this->belongsTo(User::class, 'user_id', 'id');
}
public function bookings(){
return $this->hasMany(Booking::class);
}
Бронирование Модель Realtion
public function hall(){
return $this->belongsTo(Hall::class)->distinct();
}
Не могли бы вы вставить свои модели и отношения, которые вы определили? –