Call to a member function getId() on null

I have this error "Call to a member function getId() on null" when converting from v2 to v3 In AdminPanelProvider.php
->userMenuItems([
MenuItem::make()
->label('Change Password')
->url(UserResource::getUrl('changePassword')) // <-error
->icon('heroicon-s-cog'),
])
->userMenuItems([
MenuItem::make()
->label('Change Password')
->url(UserResource::getUrl('changePassword')) // <-error
->icon('heroicon-s-cog'),
])
In UserResource
public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
'changePassword' => Pages\ChangePassword::route('/change-password'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
'changePassword' => Pages\ChangePassword::route('/change-password'),
];
}
Solution:
Try putting it in a Closure to evaluate it later (if that's supported here) ->url(fn () => UserResource::getUrl('changePassword'))) The issue is, that for the URL you need the current Panel, but you are just in the process of defining that panel....
Jump to solution
7 Replies
Dennis Koch
Dennis Koch16mo ago
Why are you opening multiple threads with the same issue? https://discord.com/channels/883083792112300104/1136195454015647826/1136195454015647826
neverender24
neverender24OP16mo ago
I closed the previous one
Dennis Koch
Dennis Koch16mo ago
Why? Next time please just edit your post instead of double posting. You still haven't provided the Flare exception as mentioned in #✅┊rules
neverender24
neverender24OP16mo ago
I don't intend to, and you havent tell me what spcific lacking in the previous post so I closed it I thought closing it is deleting
neverender24
neverender24OP16mo ago
Flare
Call to a member function getId() on null - The error occurred at http://localhost:8000/admin/aotps
Solution
Dennis Koch
Dennis Koch16mo ago
Try putting it in a Closure to evaluate it later (if that's supported here) ->url(fn () => UserResource::getUrl('changePassword'))) The issue is, that for the URL you need the current Panel, but you are just in the process of defining that panel.
neverender24
neverender24OP16mo ago
Thanks, it works. I thought It's the same in v2.
Want results from more Discord servers?
Add your server