Use
$this->authorize('user-activity');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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');
}
@lara32bd I didn't know you're relaying custom middleware,If you have custom middleware you need to add it to Livewire to Livewire Service provider.
However, if you are applying a custom middleware from your application the initial page-load, and want it persisted between Livewire requests, you will need to add it to this list from a Service Provider in your app.
https://livewire.laravel.com/docs/security#configuring-persistent-middleware
Please or to participate in this conversation.