1

I'm on Laravel 5.3. I can just pass variable to view by

public function test(){
    $testVar = 'test';

    return view('pages.home',compact('testVar'));
}

How can I automatically pass a variable to view without creating the variable unto the controller and then pass it to the compact argument? like

public function test(){
    return view('pages.home');
}

and then in view, I can just retrieved the variable anywhere in my application, like using the 'Auth::check()'

<div class="menu" id="primary-menu">
    {{ $menu }}
</div>

any ideas, help please?

Juliver Galleto
  • 8,831
  • 27
  • 86
  • 164

0 Answers0