我正在尝试在Laravel 5.2中创建一个新角色originating_point_user
,除了用户和管理员。为此,我创建了一个名为OriginatingPointAuth
的目录,其中有两个文件AuthController.php
和PasswordController.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
答案 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,
];