Davide Visentin
Davide Visentin

Reputation: 751

Laravel: undefined variable $component un non-cached blade views

On my local machine, launching the application with php artisan serve, everything works.

On the production server, using apache, it gives that error when the blade view is not cached.

If I run php artisan view:cache, the cached views work as expected, but the views that requires some parameter cannot be cached and thus continue to give that error.

The error is reported at an apparently random line. If I delete that line, it's reported somewhere else.

It seems to me like the view compilation works when executing the artisan command, but not during the normal execution of the application.

Example: Laravel error page

Upvotes: 0

Views: 44

Answers (1)

Davide Visentin
Davide Visentin

Reputation: 751

The solution was quite unexpected; apparently, there was something going on with apache. I solved by doing the following steps:

  • Stop apache (sudo /etc/init.d/apache2 stop on linux);
  • Clear the views cache (php artisan view:clear);
  • Start the application with php artisan serve and open it in the browser;
  • Stop php artisan serve;
  • Restart apache (sudo /etc/init.d/apache2 start).

Now everything seems to work. Don't ask me why...

Upvotes: 1

Related Questions