From 2bdce2aae5b7f51e4623c74fb4d296f69eb2cf06 Mon Sep 17 00:00:00 2001 From: Ro Date: Tue, 29 Apr 2025 14:12:12 -0600 Subject: [PATCH 1/2] add documentation on `@use` directive modifiers --- blade.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/blade.md b/blade.md index 2cf02ae0201..f4fb648b451 100644 --- a/blade.md +++ b/blade.md @@ -658,6 +658,32 @@ If you have multiple classes within the same namespace, you may group the import @use('App\Models\{Flight, Airport}') ``` +The `@use` directive also supports importing PHP functions and constants by prefixing the import path with the `function` or `const` modifiers. For example, to import a function, you may use: + +```blade +@use(function App\Helpers\format_currency) +``` + +Similarly, to import a constant: + +```blade +@use(const App\Constants\MAX_ATTEMPTS) +``` + +Just like class imports, aliases are supported for functions and constants as well: + +```blade +@use(function App\Helpers\format_currency, 'formatMoney') +@use(const App\Constants\MAX_ATTEMPTS, 'MAX_TRIES') +``` + +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: + +```blade +@use(function App\Helpers\{format_currency, format_date}) +@use(const App\Constants\{MAX_ATTEMPTS, DEFAULT_TIMEOUT}) +``` + ### Comments From 3c7602ff782aee305d3ea2e0b658638b05edbbb5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 29 Apr 2025 15:50:32 -0500 Subject: [PATCH 2/2] Update blade.md --- blade.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/blade.md b/blade.md index f4fb648b451..a483b2abe89 100644 --- a/blade.md +++ b/blade.md @@ -658,18 +658,12 @@ If you have multiple classes within the same namespace, you may group the import @use('App\Models\{Flight, Airport}') ``` -The `@use` directive also supports importing PHP functions and constants by prefixing the import path with the `function` or `const` modifiers. For example, to import a function, you may use: +The `@use` directive also supports importing PHP functions and constants by prefixing the import path with the `function` or `const` modifiers: ```blade @use(function App\Helpers\format_currency) ``` -Similarly, to import a constant: - -```blade -@use(const App\Constants\MAX_ATTEMPTS) -``` - Just like class imports, aliases are supported for functions and constants as well: ```blade