might sound a daft question, but you installed your package?
Running Artisan Command Breaks my View Composer
I have a View Composer helper that is added to all views. It's for customizing a class on the <body> tag. This will be used for CSS if I need something custom for a specific page.
It's setup like this in a package routes.php
View::composer('*', function($view) {
$name = str_replace('::', '_', $view->getName());
$name = str_replace('.', '_', $name);
View::share('view_name', $name);
});
In my master.blade.php:
<body class="with-navbar {{ $view_name }}">
Please note, I am loading this View::composer from a custom package I wrote. It works just fine until I try and go through my deploy process.
This is executed at the end of my deploy script:
php artisan clear-compiled && php artisan optimize
php artisan route:cache
php artisan queue:restart
service php7.1-fpm restart
As soon as I do that and refresh the page, I get Undefined variable: view_name in my blade template. I just saw that php artisan optimize is deprecated, but I can't get my app running properly again.
How do I go about making view_name work again?
I will try your solution too @jcmargentina as it looks simpler but I was able to solve it by making a ViewComposerServiceProvider and loading it all that way. (I also now exclude php artisan optimize from my deploy scripts)
I followed this guide. https://scotch.io/tutorials/sharing-data-between-views-using-laravel-view-composers
Please or to participate in this conversation.