syh

104 经验值

public function __construct()
{

$this->middleware(['web','auth:admin']);

}
laravel5.4里,全局的中间件已经不带session和cookie那几个中间件了,改成这样就ok了,
或者路由里设置中间件

Route::Group(['prefix'=>'admin','namespace'=>'Admin','middleware' =>['web','auth:admin']],function(){

Route::get('home', 'HomeController@index')->name('admin.home');

});

当然你要先修改 Auth 认证的配置文件 config/auth.PHP
在 gurads 处,添加 admin guard 用于后台管理员认证
'guards' => [

    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'admin' => [
        'driver' => 'session',
        'provider' => 'admins',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],
],

在 providers 处添加 admins provider,使用 Admin 模型

'providers' => [

    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],

    'admins' => [
        'driver' => 'eloquent',
        'model' => App\Admin::class,
    ],
],

方法参考http://blog.csdn.net/realghost/article/details/52512268