@puankare had some sort of same issue, I ended up using ->can() middleware. I'm using Livewire v3.5.
Have something like this:
Route::get('/call-reiteration', CallReiteration::class)->can('view', CallReiteration::class);
class CallReiterationPolicy
{
public function update(?User $user, CallReiterationPools $callReiterationPool): Response
{
return $user?->client_id === $callReiterationPool->client_id
? Response::allow()
: Response::deny();
}
public function view(): bool
{
return !(auth()->user()->isSalesLogin());
}
}
and within Class, where it is needed, use
$this->authorize like $this->authorize('update', $callReiterationPool); or for view $this->authorize('view', $this);
Generate policies with this command, where you can specify the model, and based on it, laravel will generate the policy methods
php artisan make:policy PostPolicy --model=Post