Reputation: 3006
I am building a application using Laravel 5.2 and it would have both - a frontend commerce store and backend admin panel.
I want to share a set of variables (cart, company name, logo etc) to front end views. These routes are spread across a few controllers. How can I share the same variables in one go?
e.g.
My routes.php is:
Route::get('/','PagesController@showHome');
Route::get('/checkout','CartController@showCheckout');
Route::get('/login', 'PagesController@showLoginForm');
And to each of these routes/views (and not the ones in Admin panel), I want to share a variable:
$webConfig = [
'logo'=>'/[email protected]',
'company'=>'Acme Inc',
...
]
Upvotes: 0
Views: 331
Reputation: 9444
A view composer can only share a variable between views.
But if you were to opt for the following inside a service provider:
config(['web' => ['logo'=>'/[email protected]', 'company'=>'Acme Inc']]);
Now you'll have config('web.logo)
and config('web.company)
available anywhere within your app.
Upvotes: 1