2016-09-03 4 views
3

が存在していません..しかし、残念ながら、それは、クラスとして返します。ここLaravel 5.3ミドルウェアクラスは、私はミドルウェアに基づいて、いくつかの認証をしたいと思い

が存在していない私のミドルウェアは

Staff.php

ですここで
<?php 

namespace App\Http\Middleware; 

use Closure; 
use Auth; 

class Staff 
{ 
    /** 
    * Handle an incoming request. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param \Closure $next 
    * @return mixed 
    */ 
    public function handle($request, Closure $next) 
    { 
     $user = Auth::user()->type; 
     if ($user == 'S'){ 
      return $next($request); 
     } 

     return "no"; 
    } 
} 

は、私が作曲ダンプ-AUTを試してみましたkernel.php

<?php 

namespace App\Console; 

use Illuminate\Console\Scheduling\Schedule; 
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; 

class Kernel extends ConsoleKernel 
{ 
    /** 
    * The Artisan commands provided by your application. 
    * 
    * @var array 
    */ 
    protected $commands = [ 
     // 
    ]; 

    protected $middleware = [ 
     \App\http\Middleware\Staff::class, 
    ]; 

    /** 
    * Define the application's command schedule. 
    * 
    * @param \Illuminate\Console\Scheduling\Schedule $schedule 
    * @return void 
    */ 
    protected function schedule(Schedule $schedule) 
    { 
     // $schedule->command('inspire') 
     //   ->hourly(); 
    } 

    /** 
    * Register the Closure based commands for the application. 
    * 
    * @return void 
    */ 
    protected function commands() 
    { 
     require base_path('routes/console.php'); 
    } 
} 

ですそれは効果的ではありません。ここで

は私のルートです:あなたは、HTTPにミドルウェアを適用したい場合は

Route::get('/staff', 'S[email protected]')->middleware('Staff'); 

答えて

9

あなたがapp/Http/Kernel.phpに登録する必要があります呼び出します。ただし、コンソールコマンドのミドルウェアはApp\Console\Kernelに登録されています。 more on Laravel documentation

+0

カワイイを参照してください、私はそこに奇妙なコードを見たことが理由です...はいそれは私がコンソール上に置く本当だ、あなたのアイデアをありがとう、私を思い出させてくれてありがとう...ケース休館 –

関連する問題