Ich möchte einige zusätzliche Filter in meiner linken Join hinzufügen, aber ich weiß nicht, wie so freundlich mir helfen.Und auch sagen Sie mir, wie diese Abfrage in Eloquent machen kann. Meine Frage ist unten angegeben:Joins in Laravel 5.3 in einfachen und beredten
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
Benutzer- und Rollen viele zu viele Beziehung, Benutzer und Halle ein zu viele und Halle und Buchungen hat auch eine zu viele Beziehung Benutzermodell Relation
/**
* 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 verfügt über Modell Beziehung
public function user(){
return $this->belongsTo(User::class, 'user_id', 'id');
}
public function bookings(){
return $this->hasMany(Booking::class);
}
Buchung Modell real
public function hall(){
return $this->belongsTo(Hall::class)->distinct();
}
Können Sie Ihre Modelle und Beziehungen einfügen, die Sie definiert haben? –