How to Set Global Variable in Laravel?

I’m working on a Laravel and need help setting global variables. I want to use the variable for all blade templates. I have tried the below code, it’s working on a direct view template called from the controller but inside view the @extends layout, it’s not working.

View::share('settings', 'settings_value');

You can run a callback when views are rendered. There you can define which view template or layout you want to access the variable from.

View::composer('layouts.app', function($view){
    $view->with('settings', 'settings_value');
});

However, you can use 'layouts.*' , it uses a wildcard, meaning it will match any blade template within the ‘layouts’ directory. This includes ‘app’ and any other templates you might have.

If ‘layouts.app’ does not work try wildcard 'layouts.*'