Answer the question
In order to leave comments, you need to log in
Where is the best place to set a global variable in Laravel?
Where in Laravel 5 can I set a global variable that can be changed in any controller? There is an array initialized with a certain initial value, which is supplemented in some controllers, and then displayed in the main view, at the very top of the page. Where can such a variable be set? Middleware or is there something more suitable?
Answer the question
In order to leave comments, you need to log in
You do a singleton in the provider and that's it. This is how Lara works with a database connection, etc.
public function register()
{
$this->app->singleton(Connection::class, function ($app) {
return new Connection(config('riak'));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question