single ton class object and declaration

Submitted by wasiqaftab - 1 year ago

if you need to make a single ton class and you need to access that in your whole application do that in laravel 5

// do this in appservice provider in register function 
 
 $this->app->singleton('userState', function()
        {
            // connect to the oauth2 server, check grant type, client credentials....

                return  "hello";
        });
        
        // in controller using laravel 5
        \App::make('userState');  // singleton object
comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks