Skip to content

Commit 019e51a

Browse files
[12.x] Add documentation on @use directive modifiers (#10361)
* add documentation on `@use` directive modifiers * Update blade.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent b81e485 commit 019e51a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

blade.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,26 @@ If you have multiple classes within the same namespace, you may group the import
658658
@use('App\Models\{Flight, Airport}')
659659
```
660660

661+
The `@use` directive also supports importing PHP functions and constants by prefixing the import path with the `function` or `const` modifiers:
662+
663+
```blade
664+
@use(function App\Helpers\format_currency)
665+
```
666+
667+
Just like class imports, aliases are supported for functions and constants as well:
668+
669+
```blade
670+
@use(function App\Helpers\format_currency, 'formatMoney')
671+
@use(const App\Constants\MAX_ATTEMPTS, 'MAX_TRIES')
672+
```
673+
674+
Grouped imports are also supported with both function and const modifiers, allowing you to import multiple symbols from the same namespace in a single directive:
675+
676+
```blade
677+
@use(function App\Helpers\{format_currency, format_date})
678+
@use(const App\Constants\{MAX_ATTEMPTS, DEFAULT_TIMEOUT})
679+
```
680+
661681
<a name="comments"></a>
662682
### Comments
663683

0 commit comments

Comments
 (0)