未定义的变量错误 - 奇怪的情况
Undefined variable errors - strange situation
我对现有项目有疑问。
我收到消息:
ErrorException (E_ERROR) Undefined variable: errors
在我的代码中发生错误的地方是:
@if (count($errors) > 0)
我尝试安装具有相同插件和功能的新项目,并且在新项目上我没有那个问题和错误异常。
我也无法更改该文件,因为它是插件文件。
两个项目的环境是:
LEMP,
PHP: 7.1.1
Laravel: 5.5
那个错误可能是什么?
你在哪里创建的路线?
在 web.php
文件中,尝试在
中创建您的路线
Route::group(['middleware' => ['web']], function () {
//routes here
}
声明。
您可能还需要清除路由缓存
php artisan route:cache
来自文档:https://laravel.com/docs/5.5/middleware
Out of the box, Laravel comes with web and api middleware groups that
contains common middleware you may want to apply to your web UI and
API routes:
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'auth:api',
],
];
我的团队通过在 app/Http/Kernel.php 文件
中取消注释 ShareErrorsFromSession 解决了这个错误
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
我对现有项目有疑问。 我收到消息:
ErrorException (E_ERROR) Undefined variable: errors
在我的代码中发生错误的地方是:
@if (count($errors) > 0)
我尝试安装具有相同插件和功能的新项目,并且在新项目上我没有那个问题和错误异常。 我也无法更改该文件,因为它是插件文件。
两个项目的环境是:
LEMP,
PHP: 7.1.1
Laravel: 5.5
那个错误可能是什么?
你在哪里创建的路线?
在 web.php
文件中,尝试在
Route::group(['middleware' => ['web']], function () {
//routes here
}
声明。
您可能还需要清除路由缓存
php artisan route:cache
来自文档:https://laravel.com/docs/5.5/middleware
Out of the box, Laravel comes with web and api middleware groups that contains common middleware you may want to apply to your web UI and API routes:
/** * The application's route middleware groups. * * @var array */ protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, ], 'api' => [ 'throttle:60,1', 'auth:api', ], ];
我的团队通过在 app/Http/Kernel.php 文件
中取消注释 ShareErrorsFromSession 解决了这个错误\Illuminate\View\Middleware\ShareErrorsFromSession::class,