Laravel 8.69 Released

News

November 3rd, 2021

laravel8.jpg

The Laravel team released 8.69 with enum model casts, an enum validation rule, mask() method for Str and Stringable, and the latest changes in the v8.x branch.

Enum Model Casts

Mohamed Said contributed the ability for models to be cast to/from an Enum starting in PHP 8.1.

Here's an example from the pull request tests:

1 
2enum StringStatus: string
3{
4 case pending = 'pending';
5 case done = 'done';
6}
7 
8enum IntegerStatus: int
9{
10 case pending = 1;
11 case done = 2;
12}
13 
14// Model
15class EloquentModelEnumCastingTestModel extends Model
16{
17 public $timestamps = false;
18 protected $guarded = [];
19 protected $table = 'enum_casts';
20 
21 public $casts = [
22 'string_status' => StringStatus::class,
23 'integer_status' => IntegerStatus::class,
24 ];
25}

Then you can compare the model to the Enum value in your code, for example:

1if ($server->status == ServerStatus::provisioned){
2 // ...
3}

Enum Validation Rule

Mohamed Said contributed an enum validation rule that ensures the data has a corresponding value in the Enum:

1validator(
2 ['status' => 'pending'],
3 ['status' => [new Enum(ServerStatus::class)]]
4)->validate();

Use a Callback in During an Auth Attempt

@Italo contributed the ability to use a callback in the credentials array of an Auth::attempt() call:

1Auth::attempt([
2 'email' => 'john@doe.com',
3 function ($builder) {
4 $builder->where('subscription_expires_at', '<', now());
5 }
6]);

Mask Support for Str and Stringable

@Italo contributed a mask() method that masks a portion of a string with a repeated character:

1Str::mask('my-private@email.com', '*', 3);
2// my******************
3 
4Str::mask('+56 9 87654321', '*', -8, 6);
5// + 56 9 ******21

Custom Stringable Cast

Louis-Gabriel contributed a custom AsStringable cast that casts a string into a Stringable instance:

1// Illuminate\Support\Stringable instance
2$model->title->kebab();

Check out Pull Request #39410 for implementation details.

Skip Locked Support for MariaDB

Dries Vints contributed SKIP LOCKED support to the MariaDB (MySQL) engine. This update provides support for skipping locked rows when fetching records from the database.

Check out Pull Request #39396 for implantation details.

Success and Failure Command Assertions

Roberto Aguilar contributed a few convenience assertions for command exit codes within tests:

1// Before
2$this->artisan(FooCommand::class)->assertExitCode(0);
3$this->artisan(FooCommand::class)->assertExitCode(1);
4 
5// Using optional convenience methods
6$this->artisan(FooCommand::class)->assertSuccessful();
7// Assert exit code !== success (0)
8$this->artisan(FooCommand::class)->assertFailed();

Release Notes

You can see the complete list of new features and updates below and the diff between 8.68.0 and 8.69.0 on GitHub. The following release notes are directly from the changelog:

v8.69.0

Added

  • Improve content negotiation for exception handling (#39385)
  • Added support for SKIP LOCKED to MariaDB (#39396)
  • Custom cast string into Stringable (#39410)
  • Added Illuminate/Support/Str::mask() (#39393)
  • Allow model attributes to be casted to/from an Enum (#39315)
  • Added an Enum validation rule (#39437)
  • Auth: Allows to use a callback in credentials array (#39420)
  • Added success and failure command assertions (#39435)

Fixed

  • Fixed CURRENT_TIMESTAMP as default when changing column (#39377)
  • Make accept header comparison case-insensitive (#39413)
  • Fixed regression with capitalizing translation params (#39424)

Changed

  • Added bound check to env resolving in Illuminate/Foundation/Application::runningUnitTests() (#39434)

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.