I am using the Laravel view composer to share a pair of variables with all views.
app/composers.php :
View::composer('layouts.base', 'MyApp\Composers\BaseComposer');
My understanding here is that everything layouts.base uses will get the data of the composer of the view.
BaseComposer@compose , simplified:
public function compose($view) { // Some logic left out here that pulls in some data $data = array( 'name' => 'John', 'status' => 'active' ); $data = (object) $data; return $view->with('global', $data); }
Given this layouts.base :
{{ $global->name }} @include('layouts.partials.header') @yield('content')
$global->name , and this also applies to the included layouts.partials.header :
{{ $global->status }}
But a view extending layouts.base raises an Undefined variable: global error:
home.blade.php
@extends('layouts.base') @section('content') {{ $global->name }} @stop
Everything works fine if I change composers.php to the home link:
View::composer(['layouts.base', 'home'], 'MyApp\Composers\BaseComposer');
I would like to understand why, if home extends layouts.base , it cannot see view linker variables without this extra step.
php laravel laravel-4
Jkleg
source share