Skip to content

Cannot redirect user based on role #5709

Closed Answered by crynobone
HeadStudios asked this question in Q&A
Discussion options

You must be logged in to vote

You can do the following:

use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Nova;

Nova::serving(function (ServingNova $event) {
    /** @var \App\Models\User|null $user */
    $user = $event->request->user();

    if (is_null($user)) {
        return;
    }
    if ($user->hasRole('super-admin')) {
        Nova::initialPath('/resources/campaigns');
    } elseif ($user->hasRole('importer')) {
        Nova::initialPath('/csv-import');
    } else {
        // default path for other roles
        Nova::initialPath('/resources/users');
    }
});

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@HeadStudios
Comment options

@HeadStudios
Comment options

Answer selected by HeadStudios
Comment options

You must be logged in to vote
2 replies
@HeadStudios
Comment options

@feeh27
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #5708 on July 11, 2023 01:16.