Reputation: 575
So I would like to define some variables, and maybe functions in BaseController, and have them accessible within my blade templates. I did some research and View::share came up.
I have the following within my BaseController
public function __construct() {
View::share('local',"local");
}
At this point, what do I need to do so that I can access the variable $local, in my blade file (shop.blade.php) ???
I had tried just using $local, and I got "Undefined variable" error. I also tried using local() and I got "Call to undefined function" error.
What am I doing wrong?
PS: I am not using any other controllers cos I'm new to Laravel, so I'm trying out stuff little by little.
Upvotes: 0
Views: 398
Reputation: 6393
if i need to use View::share()
, i generally put it in global.php
.
simple example:
View::share('foo','bar');
in any view:
{{$foo}} //output: bar
Upvotes: 2