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'),
            ])


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'),
        ];
    }    
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.
Was this page helpful?