我想基于中间件进行一些身份验证..但不幸的是,它因类不存在而返回
这是我的中间件
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";
}
}
这是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');
}
}
我尝试过composer dump-autoload,但它并没有效果。
这是我的路线:
Route::get('/staff', 'StaffController@index')->middleware('Staff');
答案 0 :(得分:14)
如果要将中间件应用于Http调用,则应在proxy_pass
中注册它们。但是,您的中间件已在app/Http/Kernel.php
中注册为控制台命令。
见more on Laravel documentation