Skip to content

[12.x] Improve @use directive to support function and const modifiers #55583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 29, 2025

Conversation

rodolfosrg
Copy link
Contributor

@rodolfosrg rodolfosrg commented Apr 28, 2025

What's New? 🎉

The @use directive 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? 🧠💡

  • More readable 📝: No need for messy <?php tags inside Blade views!
  • Fewer lines 🧹: @use keeps your templates clean and tidy compared to multiple PHP use imports.
  • More idiomatic 🎨: Feels natural and consistent with Blade syntax, avoiding context switching between PHP and Blade.
  • Blade power-up ⚡: Leverage PHP constants and functions elegantly without breaking out of your Blade flow.
  • Future-friendly 🛡️: Makes Blade templates more maintainable and expressive!

TL;DR 🏎️

@use isn't just for classes anymore - now it's for functions and constants too!
Write cleaner, sharper Blade views without sacrificing PHP power! 🧙‍♂️✨

@taylorotwell taylorotwell merged commit d74311d into laravel:12.x Apr 29, 2025
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants