We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
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:
$this->app->when(ReportAggregator::class)
->needs('$timezone')
->giveConfig('app.timezone');
This is essentially a shorthand for:
$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β¦
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.