Laravel 5 View composer gives me an undefined variable error -
i using laravel 5, trying output categories variable view getting undefined variable error.
here code.
firstly in config/app.php:
'app\providers\appserviceprovider',
in app/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 $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 store/products.php:
@include('partials.menu')
the exact error is: undefined variable: categories resolving appreciated.
thanks
i think method "with" accepts array argument, instead try !
$categories = categories::all(); $view->with(compact('categories'));
Comments
Post a Comment