2016-04-29 2 views
0

Я просто хочу, чтобы добавить HTTP промежуточное программное обеспечение для фильтрации роли пользователя, но я получаю эту ошибку:ReflectionException - класс не существует после создания HTTP промежуточного ПО на Laravel 5

ReflectionException in Container.php line 779: Class create:comptable does not exist

in Container.php line 779 
at ReflectionClass->__construct('create:comptable') in Container.php line 779 
at Container->build('create:comptable', array()) in Container.php line 659 
at Container->make('create:comptable', array()) in Application.php line 644 
at Application->make('create:comptable') in Pipeline.php line 124 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101 
at Pipeline->then(object(Closure)) in Router.php line 703 
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 670 
at Router->dispatchToRoute(object(Request)) in Router.php line 628 
at Router->dispatch(object(Request)) in Kernel.php line 214 
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43 
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17 
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55 
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61 
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36 
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40 
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42 
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101 
at Pipeline->then(object(Closure)) in Kernel.php line 115 
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84 
at Kernel->handle(object(Request)) in index.php line 53 
at require_once('C:\wamp\www\Medecin2016\public\index.php') in server.php line 21 

И это то, что я делаю: Создать middlerware "создать":

<?php namespace App\Http\Middleware; 

use Closure; 

class CreateInfos { 

    /** 
    * Handle an incoming request. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param \Closure $next 
    * @return mixed 
    */ 
    public function handle($request, Closure $next,$comptable) 
    { 
     $User = $request->user(); 
     return ($User->hasRole($comptable)) ? $next($request) : response(view('errors.503'),401); 
    } 

} 

Установите короткое имя редактирования Kernel.php файла:

<?php namespace App\Http; 

use Illuminate\Foundation\Http\Kernel as HttpKernel; 

class Kernel extends HttpKernel { 

    /** 
    * The application's global HTTP middleware stack. 
    * 
    * @var array 
    */ 
    protected $middleware = [ 
     'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode', 
     'Illuminate\Cookie\Middleware\EncryptCookies', 
     'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', 
     'Illuminate\Session\Middleware\StartSession', 
     'Illuminate\View\Middleware\ShareErrorsFromSession', 
     'App\Http\Middleware\VerifyCsrfToken', 
    ]; 

    /** 
    * The application's route middleware. 
    * 
    * @var array 
    */ 
    protected $routeMiddleware = [ 
     'auth' => 'App\Http\Middleware\Authenticate', 
     'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth', 
     'guest' => 'App\Http\Middleware\RedirectIfAuthenticated', 
     'create' => 'App\Http\Middleware\CreateInfos', 
     'update' => 'App\Http\Middleware\UpdateInfos', 
     'delete' => 'App\Http\Middleware\DeleteInfos', 
    ]; 

} 

А добавление к промежуточному маршрутам файл:

Route::get('profile/diplomes'   ,['middleware'=>'create:comptable','uses'=>'[email protected]']); 
Route::post('profile/diplomes'   ,['middleware'=>'create:comptable','uses'=>'[email protected]']); 
Route::post('profile/update/diplomes' ,['middleware'=>'create:comptable','uses'=>'[email protected]']); 
Route::post('profile/delete/diplomes' ,['middleware'=>'create:comptable','uses'=>'[email protected]']); 
+0

Это не решает проблему, но вы могли бы объединить эти 'создать ',' update' и 'delete' middlewares в одно« промежуточное ПО », поскольку вы только проверяете, имеет ли пользователь разрешение по имени в любом случае. – James

+0

Попробуйте запустить 'rm -rf bootstrap/cache/*'. – James

+0

Я нахожусь на laravel 5? что это за команда? –

ответ

0

После изменения промежуточного слоя из маршрутов в контроллер и добавить к нему:

use App\Http\Middleware\CreateInfos; 

class ProfileFormsController extends Controller { 
    public function __construct() 
    { 
     $this->middleware('create'); 
    }