have a look at the views docs https://laravel.com/docs/5.2/views and the 'sharing data with all views' topic
Jun 16, 2016
5
Level 1
Pass variable to partial from base controller (variable must be global for all pages)
HI. I have a layout blade, and i`m including there head blade (portial). In the head i have a {{$title}} variable. I made a BaseController too, here i have a $title. So my question, how i can pass a title that it will be global, on all pages. And i want, that i can override it in specific page if i need
Level 122
Assuming that in your AppServiceProvider you include;
public function boot()
{
view()->share('siteTitle', 'The best new SaaS in the world');
}
and then in your master blade layout you have;
<title>{{ $siteTitle }}</title>
Then in your controller, you can override this by either including this line;
view()->share('siteTitle', 'My new site title');
or pass it as a variable to the view, overriding what was previously shared
$siteTitle = 'My new site title';
return view('guest.talks')->with(compact('talks','region','siteTitle'));
2 likes
Please or to participate in this conversation.