I am using Laravel 5, I am trying to pass a category variable to a view, but currently I am getting an undefined variable.
Here is the code.
First in config / app.php:
'App\Providers\AppServiceProvider',
In the application / Providers / AppServiceProvider.php:
public function boot() { View::composer('partials.menu', function($view) { $view->with('categories', Category::all()); }); }
In partials / menu.blade.php:
<ul> <li>Home</li> @foreach($categories as $category) <li><a href="/store/category/{!! $category->id !!}">{!! $category->name !!}</a></li> @endforeach <li>Basket</li> <li>Checkout</li> <li>Contact Us</li> </ul>
and in the store /products.php:
@include('partials.menu')
The exact error I get is: undefined variable: categories any help resolving this will be appreciated.
thanks
source share