-1

I have a problem with existing project. I get the message:

ErrorException (E_ERROR) Undefined variable: errors

and in my code where error occur is:

@if (count($errors) > 0)

I was try to install new project with same plugins and features and on new project I don't have that problem and error exception. Also I can't change that file, because it's plugins file.

Environment on both projects are:
LEMP,
PHP: 7.1.1
Laravel: 5.5

What can be that error?

Duka
  • 513
  • 1
  • 6
  • 19
  • 1
    Where do you have $errors defined? Where are you calling it from? – Fatimah Oct 11 '17 at 12:34
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – aynber Oct 11 '17 at 12:34
  • You're probably not defining $errors beforehand. Some environments will throw the error, some will log it silently, or not at all. – aynber Oct 11 '17 at 12:34
  • Well the error message you get is very clear? It doesnt know the variable errors. Check if the $error variable is set. `if(isset($error){}` – Merijndk Oct 11 '17 at 12:35
  • it's not problem in variable it's problem in project. On one project I don't have that notice on second I have. I'm using laravel voyager admin panel. I can't modify that file because that's the plugin. – Duka Oct 11 '17 at 12:37
  • Is the web middleware applied to that route? – Don't Panic Oct 11 '17 at 12:47
  • No, it's admin.user middleware in Voyager files. – Duka Oct 11 '17 at 12:50
  • 1
    `$errors` is usually sent when `ShareErrorsFromSession` middleware is set to run. If you don't run the middleware then you need to set the errors variable manually. – apokryfos Oct 11 '17 at 12:50
  • Thanks for answer but I want to know why I have on one project that error and don't have on other. Also, I can't change middleware, it's in the vendor folder... – Duka Oct 11 '17 at 13:02

2 Answers2

0

Where have you created the route?

Inside of the web.php file, try to create your routes within the

Route::group(['middleware' => ['web']], function () {
    //routes here
}

statement.

You may need to clear the route cache too php artisan route:cache

From the docs: 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',
    ],
];
kerrin
  • 3,376
  • 1
  • 26
  • 36
  • I wasn't create that route. I'm using voyager admin panel and he was generate route file for his routes. – Duka Oct 23 '17 at 07:37
  • I wasn't create that route. I'm using voyager admin panel and he was generate route file for his routes. In web.php I was just register that route: Voyager::routes(); Also I was add that route in web.php in web middleware group as you say but I that is not solved my problem. As a temporary solution I was set in AppServiceProvider in boot method: error_reporting(E_ALL); – Duka Oct 23 '17 at 07:50
  • Have you reported the issue to the maintainer of Voyager? – kerrin Oct 23 '17 at 07:51
  • No I was not because when I create new laravel project and install Voyager, everything works perfect, without that error. – Duka Oct 23 '17 at 07:52
0

My team was solved this error by uncomment ShareErrorsFromSession in app/Http/Kernel.php file

\Illuminate\View\Middleware\ShareErrorsFromSession::class,
Duka
  • 513
  • 1
  • 6
  • 19