A New Validation Rule and the Ability to Manually Fail a Command in Laravel 11.8

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


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.