Monday, May 20, 2024
HomeOnline BusinessLaravel 11.3 Launched - Introducing New Options

Laravel 11.3 Launched – Introducing New Options


Laravel 11.3 Released

Laravel launched Laravel 11.3 this week which incorporates a number of thrilling options designed to boost your growth workflow. These options embody multi-line textarea enter in Laravel Prompts, pull and pullHidden() strategies, and hasAny methodology for enhanced session administration.

Multi-line Textarea Enter in Laravel Prompts

Laravel 11.3 provides help for multi-line textarea inputs in Laravel Prompts. That is notably helpful when detailed textual content inputs are crucial, equivalent to consumer bios, descriptions, or another prolonged enter. Right here’s the way you would possibly implement it:

use operate LaravelPromptstextarea;

$bio = textarea(
    label: 'Inform us about your self.',
    placeholder: 'About me...',
    required: true,
    trace: 'This can be displayed in your profile.'
);

// Including validation guidelines
$bio = textarea(
    label: 'Inform us about your self.',
    validate: fn (string $worth) => match (true) {
        strlen($worth) < 50 => 'Your bio have to be at the very least 50 characters.',
        strlen($worth) > 5000 => 'Your bio should not exceed 5,000 characters.',
        default => null
    }
);

Context pull() and pullHidden() Strategies

Laravel 11.3 additionally introduces pull() and pullHidden() strategies for the Context service, that are helpful for extracting after which eradicating knowledge from the context—excellent for situations the place transient knowledge is used throughout a request’s lifecycle.

$foo = Context::pull('foo');
$bar = Context::pullHidden('foo');

These strategies assist handle momentary knowledge with out leaving it within the world context longer than crucial, which is especially helpful for knowledge that’s solely related throughout a particular a part of the applying’s workflow, equivalent to momentary consumer states or flash messages.

New Session hasAny() Technique

The hasAny() methodology simplifies checks throughout a number of session variables, permitting you to substantiate the presence of any listed session knowledge effectively. This methodology can clear up your code, eliminating the necessity for a number of has() checks. Right here’s an instance:

// Earlier than
if (session()->has('first_name') || session()->has('last_name')) {
    // Carry out actions
}

// After utilizing hasAny()
if (session()->hasAny(['first_name', 'last_name'])) {
    // Carry out actions
}

Conclusion

These options in Laravel 11.3 supply extra nuanced management over consumer inputs and session knowledge, together with higher administration of software context. They mirror Laravel’s ongoing dedication to enhancing developer comfort and software robustness. For extra data on the entire adjustments on this replace, take a look at the official changelog.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments