Level 58
To customize the default user name in the Nova 4 User Menu, you can create a custom tool and override the renderNavigation method. Here's an example:
- Create a new tool using the
nova:toolArtisan command:
php artisan nova:tool CustomUserMenu
- In the
CustomUserMenutool class, override therenderNavigationmethod:
<?php
namespace App\Nova\Tools;
use Laravel\Nova\Nova;
use Laravel\Nova\Tool;
class CustomUserMenu extends Tool
{
public function renderNavigation()
{
$user = auth()->user();
return view('nova::partials.user', [
'user' => $user,
'name' => $user->name . ' - ' . $user->role,
'avatar' => $user->avatar(),
'url' => url(Nova::path().'/resources/users/'.$user->id),
]);
}
}
-
In the
renderNavigationmethod, we're getting the authenticated user and passing a custom name that includes the user's role. You can modify this to suit your needs. -
Finally, register the tool in the
toolsmethod of yourNovaServiceProvider:
use App\Nova\Tools\CustomUserMenu;
// ...
public function tools()
{
return [
new CustomUserMenu,
];
}
- That's it! Now when you log in to your Nova dashboard, you should see the custom user name in the User Menu.