在上传到cpanel之前我尝试了我的laravel项目并且一切正常。在我将其上传到cpanel之后,所有没有middeware工作的页面都工作正常,但中间件页面返回:
ReflectionException (-1)Class App\Http\Middleware\MyMiddleware does not exist
这是我在App \ Http \ Middleware \ MyMiddleware.php
的middewarenamespace App\Http\Middleware;
use Closure;
class MyMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(session()->has('adminId')){
return redirect('/admin/dashboard');
}else{
if($request->path() == 'admin'){
return redirect('/admin/login');
}else{
return $next($request);
}
}
}
}
这是我的App \ Http \ Kernel.php
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'myAuth' => \App\Http\Middleware\MyMiddleware::class,
];
这是我在routes / web.php的路线
Route::get('/admin', ['middleware' => 'myAuth', 'uses' => function(){
echo "nothing";}]);
到目前为止我已经尝试了
php artisan config:clear
composer update
composer dump-autoload
在上传到cpanel之前,但没有运气。
答案 0 :(得分:0)
我认为你的文件名缺少一个' l'在MyMidd' eware。
编辑器转储自动加载,然后重命名您的文件名。
我猜您的文件名和班级名称必须相同。
答案 1 :(得分:0)
对我来说有2个问题- 我在使用中间件作为路由中间件,
monitoring_api_6/app/Http/Kernel.php
有必要添加
nodeVerification' => \App\Http\Middleware\NodeVerification::class
到$routeMiddleware
数组。
第二个问题是在路由上使用中间件时,我在n
中将nodeVerification
大写了。