我的中间件(Laravel 5.8)出现以下错误: 调用未定义的函数App \ Http \ Middleware \ app()
<?php
namespace App\Http\Middleware;
use Closure;
use Carbon\Carbon;
class ProjectInterval
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$starts = Carbon::parse(config('project.start_date'));
$expires = Carbon::parse(config('project.end_date'));
$isDebug = app()->environment('local') || app()->environment('testing');
if (now()->gte($expires)) {
return redirect()->route('getDisabled');
} elseif (now()->lt($starts) && !$isDebug) {
return redirect()->route('getCountdown');
}
return $next($request);
}
}
令人惊讶的是,这仅在生产服务器上发生,而不在我的本地测试环境上发生。 我已经使用dump-autoload运行composer,但错误仍然存在。
Composer.json:
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
HTTP内核类:
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
//...
'dates' => \App\Http\Middleware\ProjectInterval::class,
//...
];
任何帮助将不胜感激。