Laravel launched Laravel 11.3 this week which incorporates a number of thrilling options designed to boost your improvement workflow. These options embrace multi-line textarea enter in Laravel Prompts, pull and pullHidden() strategies, and hasAny technique 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 significantly helpful when detailed textual content inputs are crucial, corresponding to person bios, descriptions, or another prolonged enter. Right here’s the way you may implement it:
$bio = textarea(
label: ‘Inform us about your self.’,
placeholder: ‘About me…’,
required: true,
trace: ‘This will likely 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 should be a minimum of 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—ultimate for situations the place transient knowledge is used throughout a request’s lifecycle.
$bar = Context::pullHidden(‘foo’);
These strategies assist handle short-term knowledge with out leaving it within the international context longer than crucial, which is especially helpful for knowledge that’s solely related throughout a selected a part of the appliance’s workflow, corresponding to short-term person states or flash messages.
New Session hasAny() Methodology
The hasAny() technique simplifies checks throughout a number of session variables, permitting you to verify the presence of any listed session knowledge effectively. This technique can clear up your code, eliminating the necessity for a number of has() checks. Right here’s an instance:
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 provide extra nuanced management over person inputs and session knowledge, together with higher administration of utility context. They replicate Laravel’s ongoing dedication to bettering developer comfort and utility robustness. For extra data on the entire adjustments on this replace, try the official changelog.