Quite often, in Laravel, you need to inject configuration values into an object using the service container. To do so, there's a function called giveConfig which can be used for that. An example:

<?php

$this->app->when(ReportAggregator::class)
    ->needs('$timezone')
    ->giveConfig('app.timezone');

This is essentially a shorthand for:

<?php

$this->app->when(ReportAggregator::class)
    ->needs('$timezone')
    ->give(fn () => config('app.timezone'));

It's one of those many small constructs in Laravel that make your code easier to read…

Related Posts

  • Optimising large whereIn queries in Laravel
  • How to get request parameters in Laravel
  • Laravel Service Provider in Simple English
  • Customising lazy-loading prevention in Laravel
  • Testing for equal json strings in Laravel tests