laravel: extend any service from container

Laravel has a very powerful and useful Service Container and you can extend any service from the Laravel Container any time. For that, you can use the extend() method to decorate or configure the resolve services from the container. 

to decorate the service:

$this->app->extend(ExampleService:class, function ($service, $app) {
  return new DecoratedExampleService($service);
});

to configure the service:

$this->app->extend('url', function (UrlGeneratorContract $url, $app) {
  $url->setSessionResolver(function () {
    return $this->app['session'] ?? null;
  });
  return $url;
});