Mastering Laravel 10.35: Blade Use Directives and Maintenance Secrets
Overview
Prerequisites
To follow this tutorial, you should have a baseline understanding of
Key Libraries & Tools
- Laravel: The core framework providing the new features.
- Blade: Laravel's powerful templating engine used for the new
@usedirective. - Artisan: The command-line interface for managing maintenance mode.
The New @use Blade Directive
Before this release, importing a class into a @php block. Now, we use the cleaner @use directive.
{{-- The old, verbose way --}}
@php use Illuminate\Support\Number; @endphp
{{-- The new, streamlined way --}}
@use('Illuminate\Support\Number')
{{-- You can even alias classes --}}
@use('Illuminate\Support\Number', 'Num')
This syntax mirrors standard
Smarter UI with Number Abbreviation
When building dashboards, space is a premium. The Number::abbreviate method provides a concise way to display large metrics without cluttering the interface.
use Illuminate\Support\Number;
// Returns "123K"
echo Number::abbreviate(123000);
// Returns "1M"
echo Number::abbreviate(1000000);
This method automatically handles scales from thousands to trillions, ensuring your UI scales alongside your data.
Enhanced Maintenance Mode
down command now supports a --secret flag without requiring a manual value. This generates a random string and provides a clickable URL immediately.
# Generate a random secret for maintenance bypass
php artisan down --secret
This prevents unauthorized access while allowing developers to test the live site via a unique, temporary URL.
Syntax Notes
The @use directive is a directive-level implementation of the use keyword. Unlike @php, it specifically targets class imports, which prevents logic from leaking into your views. The Number::abbreviate method is part of the Illuminate\Support\Number utility, which centralizes formatting logic previously scattered across various helpers.
Tips & Gotchas
Always remember to use the --secret flag when taking a production site down. Without it, you might lock yourself out of the front-end validation process. For
