gpt4 book ai didi

php - Laravel 5.3 中间件类不存在

转载 作者:可可西里 更新时间:2023-11-01 13:37:35 24 4
gpt4 key购买 nike

我想基于中间件进行一些身份验证..但不幸的是它返回因为类不存在

这是我的中间件

员工.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');

最佳答案

如果您想将中间件应用于 Http 调用,您应该在 app/Http/Kernel.php 中注册它们。但是,您的中间件已在 App\Console\Kernel 中注册用于控制台命令。参见 more on Laravel documentation

关于php - Laravel 5.3 中间件类不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39304881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com