Laravel developers, friendly reminder: always put your orWhere queries carefully 👀
Always try to put them in a separate where 👌
Back
It will take hidden posts too if they have the active status 😬
•
This will work correctly but if you want to add 3rd where which is not dependent with active status if it fails it still takes that entry as it has status active.
$users = User::query()
->where('role', 'admin')
->orWhere('status', 'active')
->get();
•
So if you add something like this..
$users = User::query()
->where('is_visible', true)
->where('role', 'admin')
->orWhere('status', 'active')
->get();
It will take hidden posts too if they have the active status 😬
•
In response to @MrPunyapal
The correct solution will be...
$users = User::query()
->where('is_visible', true)
->where(function (Builder $query) {
$query->where('role', 'admin')
->orWhere('status', 'active');
})
->get();
•