set global variable which change value dynamically in laravel code example

Example 1: laravel set config value dynamically

Config::set('custom.my_val', 'mysinglelue');

Example 2: laravel use global variable in model

SET configuration variables at runtime:
class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        View::share('key', 'value');
        Schema::defaultStringLength(191);
        $company=DB::table('company')->where('id',1)->first();
        config(['yourconfig.company' => $company]);
    }
}

USE:
config('yourconfig.company');

Tags:

Php Example