Did you setup your binding in a service provider? If yes have you thought about adding your service provider to the config/app.php file?
May 5, 2015
5
Level 3
View Composer : bind composer to a partial
I'm trying to figure out whether it is possible to bind a composer to a partial.
I have a template partial navigation.blade.php which I then include within the main layout.blade.php file.
I've set up the binding
view()->composer(
'admin.template.partials.navigation',
'Cmd\Composers\Admin\MainNavigation'
);
and my MainNavigation class looks like this
class MainNavigation implements Contract {
/**
* @var Guard
*/
private $guard;
/**
* @param Guard $guard
*/
public function __construct(Guard $guard)
{
$this->guard = $guard;
}
/**
* Bind user's first name to the view.
*
* @param View $view
*/
public function compose(View $view)
{
$view->with('userName', $this->guard->user()->first_name);
}
}
I then include the partial in my layout
@include('admin.template.partials.navigation')
and from within the partial blade view I simply call the variable $userName (within curly brackets), but when I run it I get
ErrorException in fc84a079a60140648eee92d4f9e5e88b line 20: Undefined variable: userName (View: /home/vagrant/Code/framework/resources/views/admin/template/partials/navigation.blade.php) (View: /home/vagrant/Code/framework/resources/views/admin/template/partials/navigation.blade.php) (View: /home/vagrant/Code/framework/resources/views/admin/template/partials/navigation.blade.php)
Any idea?
Level 3
I've found the problem - and it was related to some changes I've done earlier. It works fine now.
Please or to participate in this conversation.