BangularTK
BangularTK

Reputation: 554

Dynamically remove service provider in Laravel

Is there a way to dynamically remove a service provider from the 'providers' array in config/app.php?

Upvotes: 2

Views: 3592

Answers (2)

Yevgeniy Afanasyev
Yevgeniy Afanasyev

Reputation: 41350

if you want to remove a service from service provider, just make it null.

app()->instance(SomeClass::class, null);

Upvotes: 1

Filip Koblański
Filip Koblański

Reputation: 9988

You can place the service providers registration in app service provider in the register method:

public function register()
{
    if ($yourConfition) {
        $this->app->register('SpecifiedServiceProvider');
    }
}

and of course remove it from config.

Upvotes: 1

Related Questions