Hi!
I guess you have these relationships on your Notice model:
notices_to_districts, notices_to_employees and notices_to_establishments.
Then try this:
$notices = Notice::where(function ($q) use ($district_id, $user_id, $establishment_id) {
$q
->orWhereHas('notices_to_districts', function ($q) use ($district_id) {
$q->where('district_id', $district_id);
})
->orWhereHas('notices_to_employees', function ($q) use ($user_id) {
$q->where('user_id', $user_id);
})
->orWhereHas('notices_to_establishments', function ($q) use ($establishment_id) {
$q->where('establishment_id', $establishment_id);
});
})->get();
If you want to debug your query and see sql statement:
$query = Notice::where(function ($q) use ($district_id, $user_id, $establishment_id) {
$q
->orWhereHas('notices_to_districts', function ($q) use ($district_id) {
$q->where('district_id', $district_id);
})
->orWhereHas('notices_to_employees', function ($q) use ($user_id) {
$q->where('user_id', $user_id);
})
->orWhereHas('notices_to_establishments', function ($q) use ($establishment_id) {
$q->where('establishment_id', $establishment_id);
});
});
dd($query->toSql());