在Laravel 5.2

时间:2016-08-03 08:32:22

标签: authentication laravel-5.2 role

我正在尝试在Laravel 5.2中创建一个新角色originating_point_user,除了用户和管理员。为此,我创建了一个名为OriginatingPointAuth的目录,其中有两个文件AuthController.phpPasswordController.php。同时修改了kernal.php,如下所示:

protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'admin' => \App\Http\Middleware\RedirectIfNotAdmin::class,
        'origination_point_user' => \App\Http\Middleware\RedirectIfNotOriginationpointUser::class,
    ];

auth.php

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

        'admins' => [
            'driver' => 'eloquent',
            'model' => App\Admin::class,
        ],
        'originating_point_users' => [
            'driver' => 'eloquent',
            'model' => App\OriginatingPointUser::class,
        ]
        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

但是当我尝试使用originating_point_user中间件访问路线时,会显示

  

Container.php第734行中的ReflectionException:Class   originating_point_user不存在

路线:

Route::group(['prefix'=>'originating-point-user'], function() {
    Route::group(['prefix'=>'loading-details'], function() {
        Route::get('/add', [
            'as' => 'opu.loading_details.create',
            'middleware' => ['originating_point_user'],
            'uses' => 'OrdersController@add_loading_details'
        ]);
    });
});

此外,它不会重定向到AuthController.php

中定义的提及页面

1 个答案:

答案 0 :(得分:1)

在您的内核文件中,您已将中间件注册为origination_point_user而不是originating_point_user。当您使用originating_point_user调用中间件时。

protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'admin' => \App\Http\Middleware\RedirectIfNotAdmin::class,
 //change here originating_point_user
           'originating_point_user' => \App\Http\Middleware\RedirectIfNotOriginationpointUser::class,
    ];