Mastering Laravel 10.35: Blade Use Directives and Maintenance Secrets

Laravel////3 min read

Overview

continues the framework's tradition of refining developer experience by reducing boilerplate. This update introduces more expressive directives, smarter number formatting, and enhanced security for maintenance mode. These features prioritize code readability and administrative flexibility.

Prerequisites

To follow this tutorial, you should have a baseline understanding of and the framework. Familiarity with templating and basic CLI commands is essential.

Key Libraries & Tools

  • : The core framework providing the new features.
  • : Laravel's powerful templating engine used for the new @use directive.
  • : The command-line interface for managing maintenance mode.

The New @use Blade Directive

Before this release, importing a class into a file required a clunky @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 imports, keeping your templates lean and readable.

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

's 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 imports, use aliases if you find yourself dealing with long class names or potential naming collisions within the template context.

Topic DensityMention share of the most discussed topics · 14 mentions across 4 distinct topics
36%· products
21%· products
21%· products
21%· products
End of Article
Source video
Mastering Laravel 10.35: Blade Use Directives and Maintenance Secrets

The New Use Directive, Abbreviate Numbers & Artisan Down With Secret

Watch

Laravel // 4:14

The official YouTube channel of Laravel, the clean stack for Artisans and agents. We will update you on what's new in the world of Laravel, from the framework to our products Cloud, Forge, and Nightwatch.

Who and what they mention most
3 min read0%
3 min read