8

I would like to remove dashboard from my Laravel Nova app.

I found it easy to remove it from sidebar-menu - simply comment /views/dashboard/navigation.blade.php code.

However, I want to add a redirection logic (landing page depends on user role) so when navigating to / user will be redirected to a resource or tool which corresponds him.

(I have already implemented a redirection after login (https://stackoverflow.com/a/54345123/1039488)

I tried to do it with cards, but looks like this is not the right solution.

Any idea where can I place the redirection logic?

guyaloni
  • 4,972
  • 5
  • 52
  • 92

5 Answers5

6

Nova 4; You can override the initialPath like so:

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        Nova::initialPath('/resources/users');
    }

    // ...
}

This way, you get redirected to the Users resource upon logging in.

Ron van der Heijden
  • 14,803
  • 7
  • 58
  • 82
3

Pre nova 4 method:

To NovaServiceProvider.php add to boot method:

Nova::script('menuFix', __DIR__.'/../../resources/js/fixMenu.js');

Create file fixMenu.js with following:

if (location.pathname == '/' || location.pathname == '/dashboards/main'){
    location.href = '/whereToRedirect'
}
1

A cleaner and safe way for Nova 3.x or below:

  • Copy vendor/laravel/nova/resources/views/layout.blade.php to resources/views/vendor/nova/
  • Now open resources/views/vendor/nova/layout.blade.php and edit it
  • Replace this line with the code below window.Nova = new CreateNova(config);
    window.Nova = new CreateNova(config);
    window.Nova.booting((Vue, router, store) => {
        /** This fixes showing an empty dashboard. */
        router.beforeEach((to, from, next) => {
            if (to.name === 'dashboard.custom') {
                next({ name: 'index', params: { resourceName: 'users'}});
            }

            next();
        });
    });
  • Replace users with your entity name's plural like products
  • Now save the file and refresh the nova dashboard and you should see the new page.

The solution was taken from here with clear steps.

The solution may also work for 4.x, but I haven't checked it yet.

Happy Coding :)

Imran Zahoor
  • 2,521
  • 1
  • 28
  • 38
0

Just figured this out myself. In your Routes/web.php file, add a redirect route:

Route::redirect('/','/resources/{resource_name}');

where {resource_name} is the plural form of the resource. For example, '/resources/posts'.

In your case, you may want to redirect to your own control file, where the redirect logic can be placed.

Route::get('/', 'YourController@rootRedirectLogic');

Then in the controller YourController, add the method:

public function rootRedirectLogic(Request $request) {
    // some logic here
    return redirect()->route('YourRoute');
}

where 'YourRoute' is the name of the route you want to send the user to.

(Found clues to this solution in a comment by dillingham here: https://github.com/laravel/nova-issues/issues/393)

lwitzel
  • 591
  • 5
  • 15
  • It doesn't work. Something it's overwriting the redirect in 'routes' – Tudor-Radu Barbu Mar 14 '19 at 10:54
  • @Tudor-RaduBarbu Try moving the route earlier in the file. Laravel uses the first matched route, and I find a Resource:: route will often block more specific routes below it. – lwitzel Mar 20 '19 at 22:15
0

i came across this link : Laravel Nova - Point Nova path to resource page

Not sure it's a permanent solution but editing LoginController.php will do.

public function redirectPath()
{
    return Nova::path().'/resources/***<resource_name>***;
}

**change to your own resource name

Jerry Chee
  • 11
  • 4