Skip to content

Commit ecd78bb

Browse files
committed
added tip #324
1 parent eb1c688 commit ecd78bb

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Currently, there are over 300 tips categorized as follows:
2121
- 🖼️ [View Tips](./tips/views.md) (10 tips)
2222
- 📬 [Queues & Job Tips](./tips/queues-and-jobs.md) (9 tips)
2323
- 🔒 [Authentication & Authorization Tips](./tips/auth.md) (6 tips)
24-
- 📦 [Laravel Container Tips](./tips/container.md) (5 tips)
24+
- 📦 [Laravel Container Tips](./tips/container.md) (6 tips)
2525
- ⚠️ [Error Handling Tips](./tips/error-handling.md) (4 tips)
2626

2727
If you have new tips or suggestions for improving existing ones, feel free to drop a PR!

tips/container.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [Check Your Application Enviroment](#laravel-tip--check-your-application-enviroment-️)
66
- [The New "optimizes" Method](#laravel-tip--the-new-optimizes-method-️)
77
- [Deferred Providers](#laravel-tip--deferred-providers-️)
8+
- [Binding Primitives to Config Values](#laravel-tip--binding-primitives-to-config-values-️)
89

910
## Laravel Tip 💡: Use rebinding events to refresh dependencies ([⬆️](#container-tips-cd-))
1011

@@ -142,3 +143,23 @@ class RiakServiceProvider extends ServiceProvider implements DeferrableProvider
142143
}
143144
}
144145
```
146+
147+
## Laravel Tip 💡: Binding Primitives to Config Values ([⬆️](#container-tips-cd-))
148+
149+
Sometimes, you might need to bind a primitive to a value, such as a config value. Instead of using "give()" with a callback, Laravel ships with the "giveConfig" shortcut to do exactly that 🚀
150+
151+
```php
152+
<?php
153+
154+
// Instead of this 🥱
155+
app()
156+
->when(GitHub::class)
157+
->needs('$apiKey')
158+
->give(fn() => config('services.github.api-key'));
159+
160+
// You can do this 🔥
161+
app()
162+
->when(GitHub::class)
163+
->needs('$apiKey')
164+
->giveConfig('services.github.api-key');
165+
```

0 commit comments

Comments
 (0)