Reputation: 3
I'm currently working on a project in FilamnentPHP v3 and Laravel 11 and I am trying to figure out how to pass the current user_id as a parameter in my AdminPanelProvider to a function in the same class.
My AdminPanelProvider class
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->brandName(fn() => auth()->user()->name ?? 'Reporting System') // auth here in brandName is working fine
->brandLogo(asset('logo.png'))
->brandLogoHeight('4rem')
->colors([
'primary' => Color::Red,
])
->sidebarCollapsibleOnDesktop()
->navigationItems(self::NavigationReportList(fn()=>auth()->user()->id)) // here is my problem
// rest of Panel function code
.....
}
public static function NavigationReportList($userId)
{
dd($userId,Auth()->id(),fn()=>Auth()->id()); // can't get auth id with the three options
[The dd data that i get when trying to get the closure auth id attached below]
$reports = Report::whereHas('users', function ($query) {
$query->where('users.id', auth()->id());
})
->select('id')
->orderBy('id', 'desc')
->limit(4)
->pluck('id')
->toArray();
// rest of my code
.....
}
So all i want to is to get the auth id inside the static function NavigationReportList
any help will be appreciated
picture of dd of auth id https://i.sstatic.net/7A8JyxCe.jpg
Upvotes: 0
Views: 285
Reputation: 277
Try using
->navigationItems(self::NavigationReportList(auth()->user()->id))
You must pass the id
as a parameter. When you use fn() => auth()->id()
, a function is passed as a parameter, not the id
. In brandName
, it works because it is a filament function, and filament can handle closures.
Upvotes: 0