Search code examples
global-variableslaravel-8laravel-routing

Global Variable in Laravel 8


I am using Laravel 8. I need a Global variable which will be available in all Views (Blade files).

This Global variable will update using some API call with every route call.

How can I create this Global Variable ?


Solution

  • You can define your global variables in AppServiceProvider in boot method:

     public function boot()
        {
            $value = "myGlobal";
            View::share('key', $value);
        }
    

    read this documentation : Sharing Data With All Views