Если вы уже определили отношение между App\User
и App\Room
такими моделями.
class User {
/* other codes in your model goes here */
public function rooms(){
return $this->hasMany(App\Room::class);
}
}
class Room {
/* other codes in your model goes here */
public function user(){
return $this->belongsTo(App\User::class);
}
}
Вы можете получить электронную почту всех пользователей с комнатами, в которых статус комнат указан в списке, как этот
$users= \App\User::with(['rooms' => function($query){
$query->where('status', 'listed');
}])->pluck('email');