[12.x] Improve @use directive to support function and const modifiers #55583
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's New? π
The
@usedirective in Laravel just got a major upgrade!Before, it only supported two parameters: a path and an alias.
Now you can also specify function π§© or const π₯ imports directly within Blade templates!
β Example
@use(function App\Helpers)@use(const App\Constants\MY_LITTLE_CONST, MY_LITTLE_ALIAS)β Grouped imports still work beautifully
@use(function App\Helpers\{foo, bar})@use(const App\Constants\{FOO, BAR})β Paths still work with or without leading slashes
@use(function \App\Helpers)Why is this awesome? π§ π‘
<?phptags inside Blade views!@usekeeps your templates clean and tidy compared to multiple PHP use imports.TL;DR ποΈ
@useisn't just for classes anymore - now it's for functions and constants too!Write cleaner, sharper Blade views without sacrificing PHP power! π§ββοΈβ¨