Get expert guidance in a few days with a Laravel code review

Laravel 8.13 Released

Published on by

Laravel 8.13 Released image

Never Miss a Laravel Release 🚀

Sign up and get an email with each new Laravel release

The Laravel team released 8.13 this week and updated the changelog detailing all the new features in last week’s 8.12 release. The new features added to Laravel over the previous few weeks are packed with exciting framework updates, so let’s look at what’s new!

8.12: Create Observers With a Custom Path

@StefanoDucciConvenia contributed the ability to use stubs with the make:observer command (#34911).

8.12: Lazy Method in 8.x Eloquent Factory

Mathieu TUDISCO contributed the ability to create a callback that persists a model in the database when invoked. In previous versions of Laravel, the FactoryBuilder had a lazy() method that only creates a record if called. Now, 8.x factories can do the same:

$factory = User::factory()->lazy();
$factory = User::factory()->lazy(['name' => 'Example User']);
 
$factory();

8.12: Encrypted String Eloquent Cast

Jason McCreary contributed an eloquent cast that will handle encryption and decryption of a simple string:

public $casts = [
'access_token' => 'encrypted',
];

8.12: New DatabaseRefreshed Event

Adam Campbell contributed a new DatabaseRefreshed event that fires right after both a migrate:fresh and migrate:refresh command. The new event allows developers to perform secondary actions after refreshing the database. You may use the event class from the following namespace:

\Illuminate\Database\Events\DatabaseRefreshed::class

8.12: New withColumn() to support Aggregate Functions

Khalil Laleh contributed a withColumn method to support more SQL aggregation functions like min, max, sum, avg, etc. over relationships:

Post::withCount('comments');
Post::withMax('comments', 'created_at');
Post::withMin('comments', 'created_at');
Post::withSum('comments', 'foo');
Post::withAvg('comments', 'foo');

You might want to check out Pull Request #34965 for more details.

8.12: Add explain() to Eloquent/Query Builder

Illia Sakovich contributed an explain() method to the query builder/eloquent builder, which allows you to receive the explanation query from the builder:

Webhook::where('event', 'users.registered')->explain()
 
Webhook::where('event', 'users.registered')->explain()->dd()

Now you can call explain() to return the explanation or chain a dd() call to die and dump the explanation.

8.12: Full PHP 8 Support

Dries Vints has been working on adding PHP 8 support to the Laravel ecosystem, which involves various libraries (both first- and third-party libraries) and coordination of many efforts. A HUGE thanks to Dries and all those involved in getting Laravel ready for the next major PHP version!

8.12: Route Registration Methods

Gregori Piñeres contributed some route regex registration methods to easily define route params for repetitive, regular expressions you might add to route params:

// Before. This is still a valid, acceptable way of defining routes
Route::get('authors/{author}/{book}')
->where([
'author' => '[0-9]+',
'book' => '[a-zA-Z]+'
]);
 
// New optional syntax
Route::get('authors/{author}/{book}')
->whereNumber('author')
->whereAlpha('book');
 
// New methods support multiple args
Route::get('authors/{author}/{book}')
->whereAlpha('author', 'book');

8.12: Don’t Release Option for Job Rate Limiting

Paras Malhotra contributed a dontRelease() option for RateLimited and RateLimitedWithRedis job middleware:

public function middleware()
{
return [(new RateLimited('backups'))->dontRelease()];
}

When called, the dontRelease() method will not release the job back to the queue when the job is rate limited.

8.13: Aggregate Load Methods

In 8.12, Khalil Laleh contributed the withColumn() method to support aggregate functions. In 8.13, he contributed load* methods for aggregate functions:

public function loadAggregate($relations, $column, $function = null)
public function loadCount($relations)
public function loadMax($relations, $column)
public function loadMin($relations, $column)
public function loadSum($relations, $column)
public function loadAvg($relations, $column)

8.13: Add chunk() to Fluent Strings

Chris Kankiewicz contributed a chunk() method to fluent strings which allows a string to be chunked by a specific length:

// returns a collection
Str::of('foobarbaz')->chunk(3);
 
// Returns 'foo-bar-baz'
Str::of('FooBarBaz')->lower()->chunk(3)->implode('-');

Release Notes

You can see the full list of new features and updates below and the diff between 8.11.0 and 8.12.0 and 8.12.0 and 8.13.0 on GitHub. The following release notes are directly from the changelog: *

v8.13.0

Added

  • Added loadMax() | loadMin() | loadSum() | loadAvg() methods to Illuminate\Database\Eloquent\Collection. Added loadMax() | loadMin() | loadSum() | loadAvg() | loadMorphMax() | loadMorphMin() | loadMorphSum() | loadMorphAvg() methods to Illuminate\Database\Eloquent\Model (#35029)
  • Modify Illuminate\Database\Eloquent\Concerns\QueriesRelationships::has() method to support MorphTo relations (#35050)
  • Added Illuminate\Support\Stringable::chunk() (#35038)

Fixed

  • Fixed a few issues in Illuminate\Database\Eloquent\Concerns\QueriesRelationships::withAggregate() (#35061, #35063)

Changed

  • Set chain queue | connection | delay only when explicitly configured in (#35047)

Refactoring

  • Remove redundant unreachable return statements in some places (#35053)

v8.12.0

Added

  • Added ability to create observers with custom path via make:observer command (#34911)
  • Added Illuminate\Database\Eloquent\Factories\Factory::lazy() (#34923)
  • Added ability to make cast with custom stub file via make:cast command (#34930)
  • ADDED: Custom casts can implement increment/decrement logic (#34964)
  • Added encrypted Eloquent cast (#34937, #34948)
  • Added DatabaseRefreshed event to be emitted after database refreshed (#34952, f31bfe2)
  • Added withMax()|withMin()|withSum()|withAvg() methods to Illuminate/Database/Eloquent/Concerns/QueriesRelationships (#34965, f4e4d95, #35004)
  • Added explain() to Query\Builder and Eloquent\Builder (#34969)
  • Make multiple_of validation rule handle non-integer values (#34971)
  • Added setKeysForSelectQuery method and use it when refreshing model data in Models (#34974)
  • Full PHP 8.0 Support (#33388)
  • Added Illuminate\Support\Reflector::isCallable() (#34994, 8c16891, 31917ab, 11cfa4d, #34999)
  • Added route regex registration methods (#34997, 3d405cc, c2df0d5)
  • Added dontRelease option to RateLimited and RateLimitedWithRedis job middleware (#35010)

Fixed

  • Fixed check of file path in Illuminate\Database\Schema\PostgresSchemaState::load() (268237f)
  • Fixed: PhpRedis (v5.3.2) cluster – set default connection context to null (#34935)
  • Fixed Eloquent Model loadMorph and loadMorphCount methods (#34972)
  • Fixed ambigious column on many to many with select load (5007986)
  • Fixed Postgres Dump (#35018)

Changed

  • Changed make:factory command (#34947, 4f38176)
  • Make assertSee, assertSeeText, assertDontSee and assertDontSeeText accept an array (#34982, 2b98bcc)
Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
The Inertia v3 Beta is Here image

The Inertia v3 Beta is Here

Read article
Polyscope Is an Ai-First Dev Environment for Orchestrating Agents image

Polyscope Is an Ai-First Dev Environment for Orchestrating Agents

Read article
Filament v5.3.0 Released with Deferred Tab Badges and Column Manager Improvements image

Filament v5.3.0 Released with Deferred Tab Badges and Column Manager Improvements

Read article
Ward: A Security Scanner for Laravel image

Ward: A Security Scanner for Laravel

Read article
Kit: An Opinionated API Starter Kit for Laravel image

Kit: An Opinionated API Starter Kit for Laravel

Read article
Livewire v4.2.0 Released with Security Hardening and Laravel 13 Support image

Livewire v4.2.0 Released with Security Hardening and Laravel 13 Support

Read article