laravel我做了前后台登陆,后台未登录跳转到前台登陆页面了。 我想让后台未登入跳转到后台登陆页面,前台未登陆跳转到前台登陆页面。
config\auth.php
添加guards中的admin和providers中的admins
<?php 'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ], 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', ], 'admin' => [ 'driver' => 'session', 'provider' => 'admins', ], ], 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\User::class, ], 'admins' => [ 'driver' => 'eloquent', 'model' => App\AdminUser::class, ], ], 'passwords' => [ 'users' => [ 'provider' => 'users', 'table' => 'password_resets', 'expire' => 60, ], ],
路由
//登陆页面 Route::get('/login', "\App\Http\Controllers\LoginController@index")->name('login'); //登陆行为 Route::post('/login', "\App\Http\Controllers\LoginController@login"); Route::group(['middleware' => 'auth:web'],function (){ Route::get('/posts', '\App\Http\Controllers\PostController@index'); } //后台 Route::group(['prefix' => 'admin'], function() { Route::get('/login', '\App\Admin\Controllers\LoginController@index'); Route::post('/login', '\App\Admin\Controllers\LoginController@login'); Route::get('/logout', '\App\Admin\Controllers\LoginController@logout'); Route::group(['middleware' => 'auth:admin'],function (){ Route::get('/home', '\App\Admin\Controllers\HomeController@index'); }); });
遇到的页面跳转问题
侠客岛的含笑
超级无敌大坏蛋
hallo_monde