Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destroy/reset singleton in laravel way

public function register() {
    $this->app->singleton('Qwerty', function ($app) {
        return new QwertyManager();
    });
}

This is what my singleton class looks like now i want to reset the singleton object or destroy its instance via laravel. I am using 5.3

like image 723
ujwal dhakal Avatar asked Dec 23 '22 09:12

ujwal dhakal


1 Answers

You can call forgetInstance() on the service container to remove it. As the doc's say, this method can be used to Remove a resolved instance from the instance cache.

App::forgetInstance('Querty');

Next time you'll try to get an instance of this service from the container, it will be re-created using the function you provided in the singleton() method.

like image 71
jedrzej.kurylo Avatar answered Jan 08 '23 07:01

jedrzej.kurylo