Recently I created a new livewire component replacing my laravel controller, in controller method I use
Gate::authorize(‘user-activity’); which works fine.
Same Gate::authorize(‘user-activity’) works fine with the livewire component using pagination. I could easily see the page. However, when I click the next or previous page it shows ‘Not authorzied’ default page I set for the app, if I refresh the page /activity?page=5 it works again.
url /activity -> works fine url /activity?page=5 -> works fine with browser refresh but not next/prev button on the pagination link.
What I’m doing wrong here? I assume I need to set Gate::authorize(‘user-activity’) in another function, internally used by pagination next/prev action?
public function render()
{
Gate::authorize('user-activity');
$user = User::find($this->id);
return view('livewire.activity-detail', [
'username' => $user->username,
'activities' => UserActivity::where([['user_id', '=', $user->id], ['company_id', '=', $user->company_id]])->orderBy('created_at', 'desc')->paginate(50)
])
->extends('layouts.admin')
->slot('content');
}
tried
Gate::authorize('user-activity');
and
$this->authorize('user-activity');
lara32bd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.