It depends what determines the view permission; how is the ability determined; in a Policy method?
Query has() with can()
Hello,
I have this code.
->when($filters['with_at_least_two_events'], function ($query) use ($filters) {
if ($filters['with_at_least_two_events']) {
$query->has('events', '>=', 2);
}
})
Is it possible to apply a policy to take into account only the events that the connected user can see ?
I need to have something like this.
$query->has('events', '>=', 2);
// only if the connected user can see the events
if (auth()->user()->can('view', $event))
I had the idea to use whereHas() instead of has(), but how is it possible to check each event ?
Thanks for your help.
V
these are not events (events / listeners) but events in a cultural context.
This was understood from the outset.
Is there a possibility to use at the same time whereHas() and can() ? If not, I will write the code another way.
Not really; whereHas is Eloquent Builder, whereas can (when instance specific - view rather than viewAny) needs the Model instance.
Please or to participate in this conversation.