简体   繁体   中英

Laravel Admin - Voyager route redirect

I have done laravel auth with is_admin field like:

if(auth()->user()->is_admin == 1){
        return $next($request);
    }

and defined it in route so if the user is admin, can be redirected to voyager dashboard page.

Route::group(['prefix' => 'admin'], function()
{
    Voyager::routes();
    Route::get('admin', 'HomeController@admin')->middleware('admin');

});

When I login, it's redirected to specific page but with error message:

Target class [VoyagerController] does not exist.

What should I do to return voyager admin page?

You can use middleware admin.user .

Route::group(['prefix' => 'admin'], function()
{
    Voyager::routes();
    Route::get('admin', 'HomeController@admin')->middleware('admin.user');

});

Hope this will work. This will:

  1. Access route only when user is logged in.
  2. Redirect to voyager login page when accessing the restricted route.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM