This week, the Laravel team released v11.8, with a new validation rule, the ability to fail a command outside the handle()
method, create a view during make:mail, and more.
Show Events in the model:show Command
Wendell Adriel contributed an Events section to the model:show
command that displays any events defined on the $dispatchesEvents
property:
New contains
Validation Rule
Andrew Brown contributed a contains
validation rule that checks to make sure expected values are included in the given array of input:
return [
'allowed_ips' => ['present', 'nullable', 'array', 'contains:' . $request->ip()],
'allowed_ips.*' => ['required', 'ip'],
];
In the PR's description, this example ensures that the user's IP is in the allowed_ips
array. You can also pass multiple parameters, which would require that all parameters are present in the array of data. See Pull Request #51348 for more details.
Ability to Manually Fail a Command
Len Woodward contributed the ability to manually fail an Artisan command outside of the handle()
method. Like the Queue's $this->fail()
convenience method, commands can now manually fail a job:
public function handle()
{
$this->trigger_failure();
}
protected function trigger_failure()
{
$this->fail('Whoops!');
}
See Pull Request #51435 for implementation details and examples of how this method could be useful over a few other existing approaches to failing early in a command.
Create a Blade View With make:mail
Ryan Chandler contributed a --view
flag to the make:mail
command that will create an empty Blade file and configure the created Mailable
to use it by default. It works the same way as the existing --markdown
option and saves the manual step of creating and wiring up a Blade mail template.
php artisan make:mail OrderShipped --view=mail.orders.shipped
Release notes
You can see the complete list of new features and updates below and the diff between 11.7.0 and 11.8.0 on GitHub. The following release notes are directly from the changelog:
v11.8.0
- [11.x] Update PendingRequest.php by @foremtehan in https://github.com/laravel/framework/pull/51338
- Add unshift method to Collection by @timkelty in https://github.com/laravel/framework/pull/51344
- [11.x] Synchronizing cache configuration file with updated laravel v11.0.7 by @dvlpr91 in https://github.com/laravel/framework/pull/51336
- [11.x] Utilize
null-safe
operator instead of conditional check by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51328 - [11.x] Add the events to be displayed on the model:show command by @WendellAdriel in https://github.com/laravel/framework/pull/51324
- [11.x] fix: remove use of Redis::COMPRESSION_ZSTD_MIN by @calebdw in https://github.com/laravel/framework/pull/51346
- [10.x] Backport: Fix SesV2Transport to use correct
EmailTags
argument by @Tietew in https://github.com/laravel/framework/pull/51352 - [11.x] feat: use phpredis 6 in ci by @calebdw in https://github.com/laravel/framework/pull/51347
- [11.x] create new "has" validation rule by @browner12 in https://github.com/laravel/framework/pull/51348
- [11.x] Add support for previous apps keys in signed URL verification by @Krisell in https://github.com/laravel/framework/pull/51222
- [11.x] Allow setting exit code in migrate:status --pending by @brecht-vermeersch in https://github.com/laravel/framework/pull/51341
- [11.x] Fix array rule typehint by @erik-perri in https://github.com/laravel/framework/pull/51372
- [11.x] Test Improvements by @crynobone in https://github.com/laravel/framework/pull/51365
- [10.x] Fix PHPDoc typo by @staudenmeir in https://github.com/laravel/framework/pull/51390
- [11.x] Fix return type hint of resolveRouteBindingQuery by @philbates35 in https://github.com/laravel/framework/pull/51392
- [11.x] Allow adding array or string for web and api routes in bootstrap/app.php by @mrthito in https://github.com/laravel/framework/pull/51356
- [ 11.x ] Adds ability to manually fail a command from outside the handle() method by @ProjektGopher in https://github.com/laravel/framework/pull/51435
- [10.x] Fix
apa
on non ASCII characters by @faissaloux in https://github.com/laravel/framework/pull/51428 - [11.x] Compare lowercased column names in getColumnType by @chady in https://github.com/laravel/framework/pull/51431
- [11.x] Use contracts instead of concrete type for
resolveRouteBindingQuery()
by @crynobone in https://github.com/laravel/framework/pull/51425 - [11.x] Set the value of
$this
in macro closures by @simonwelsh in https://github.com/laravel/framework/pull/51401 - [11.x] Add missing roundrobin transport driver config by @u01jmg3 in https://github.com/laravel/framework/pull/51400
- [11.x] Remove unused namespace by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51436
- [11.x] Fixes doc block in
Connector.php
by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51440 - [10.x] Fixes view engine resolvers leaking memory by @nunomaduro in https://github.com/laravel/framework/pull/51450
- [11.x] Add some tests to
SupportStrTest
by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51437 - [11.x] Add isCurrentlyOwnedBy function to lock by @gazben in https://github.com/laravel/framework/pull/51393
- [11.x] Collection average/avg optimization by @bert-w in https://github.com/laravel/framework/pull/51512
- [11.x] Introduce
MixManifestNotFoundException
for handling missing Mix manifests by @xurshudyan in https://github.com/laravel/framework/pull/51502 - [11.x] MailMakeCommand: Add new
--view
option by @ryangjchandler in https://github.com/laravel/framework/pull/51411 - [11.x] Replace all backed enums with values when building URLs by @stefanvdlugt in https://github.com/laravel/framework/pull/51524
- [10.x] Do not use
app()
Foundation helper onViewServiceProvider
by @rodrigopedra in https://github.com/laravel/framework/pull/51522 - Fixes explicit route binding with
BackedEnum
by @crynobone in https://github.com/laravel/framework/pull/51525 - [11.x] Add query method to UrlGenerator contract docblock by @hjanos-bc in https://github.com/laravel/framework/pull/51515
The post A New Validation Rule and the Ability to Manually Fail a Command in Laravel 11.8 appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.