Laravel 8.76 Released

News

December 16th, 2021

laravel8.jpg

The Laravel team released 8.76 with an afterRefreshingDatabase() test method, MySQL invisible modifier support, a new string method, and the latest changes in the v8.x branch.

After Refreshing Database Test Method

Luke Downing contributed an afterRefreshingDatabase method you can use in tests when you want to seed some data in a test directly after running migrations (see the PR description for more details).

Here's an example from the pull request on how to use this method:

1abstract class TestCase extends BaseTestCase
2{
3 use CreatesApplication;
4 use LazilyRefreshDatabase;
5 
6 protected function afterRefreshingDatabase()
7 {
8 $this->artisan('db:seed', [
9 '--class' => RoleAndPermissionSeeder::class
10 ]);
11 }
12}

Customize Child Model Route Binding

@marvin-wtt contributed overriding child model route binding resolution via the resolveRouteBindingQuery method. Check out Pull Request #39929 for further details.

Common 4xx Error Status Code Boolean Checks

Adam Rodriguez contributed a forbidden() and unauthorized method to the Response class. These methods clean up logic around these statuses nicely:

1// Before
2if ($response->status() === 401) {
3 // ...
4}
5 
6if ($response->status() === 403) {
7 // ...
8}
9 
10// After
11if ($response->unauthorized()) {
12 // ...
13}
14 
15if ($response->forbidden()) {
16 // ...
17}

Invisible Modifier for MySQL Columns

Oliver Matla contributed invisible modifier support, introduced in MySQL v8.0.23. When columns are marked as invisible, they are not implicitly (i.e., SELECT *) and thus not hydrated in Laravel models. These columns can still be explicitly selected, making it useful to omit unless you explicitly need the data:

1Schema::table('users', function (Blueprint $table) {
2 $table->string('secret')->nullable()->invisible();
3});

This feature is currently only available for MySQL.

String Support for substr_replace()

Ralph J. Smit contributed substrReplace() to Str and Stringable classes:

1// Insert a string at a certain position
2$string = '1300';
3 
4$result = Str::substrReplace($string, ':', 2, 0);
5// '13:00'
6 
7// Replace the remainder of a string
8$result = (string) Str::of('Laravel Framework')
9 ->substrReplace('– The PHP Framework for Web Artisans', 8);
10// 'Laravel – The PHP Framework for Web Artisans'

Release Notes

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

v8.76.0

Added

  • Added possibility to customize child model route binding resolution (#39929)
  • Added Illuminate/Http/Client/Response::reason() (#39972)
  • Added an afterRefreshingDatabase test method (#39978)
  • Added unauthorized() and forbidden() to Illuminate/Http/Client/Response (#39979)
  • Publish view-component.stub in stub:publish command (#40007)
  • Added invisible modifier for MySQL columns (#40002)
  • Added Str::substrReplace() and Str::of($string)->substrReplace() methods (#39988)

Fixed

  • Fixed parent call in view (#39909)
  • Fixed request dump and dd methods (#39931)
  • Fixed php 8.1 deprecation in ValidatesAttributes::checkDateTimeOrder (#39937)
  • Fixed withTrashed on routes check if SoftDeletes is used in Model (#39958)
  • Fixes model:prune --pretend command for models with SoftDeletes (#39991)
  • Fixed SoftDeletes force deletion sets "exists" property to false only when deletion succeeded (#39987)
  • Fixed possible out of memory error when deleting values by reference key from cache in Redis driver (#39939)
  • Fixed Password validation failure to allow errors after min rule (#40030)

Changed

  • Fail enum validation with pure enums (#39926)
  • Remove redundant description & localize template (#39928)
  • Fixes reporting deprecations when logger is not ready yet (#39938)
  • Replace escaped dot with place holder in dependent rules parameters (#39935)
  • passthru from property to underlying query object (127334a)

Filed in:

Paul Redmond

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