Laravel 8.13 Released

Published on by

Laravel 8.13 Released image

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.

Laravel Forge logo

Laravel Forge

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

Laravel Forge
Tinkerwell logo

Tinkerwell

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

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
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
Bacancy logo

Bacancy

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

Bacancy
Lucky Media logo

Lucky Media

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

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
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
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Asymmetric Property Visibility in PHP 8.4 image

Asymmetric Property Visibility in PHP 8.4

Read article
Access Laravel Pulse Data as a JSON API image

Access Laravel Pulse Data as a JSON API

Read article
Laravel Forge adds Statamic Integration image

Laravel Forge adds Statamic Integration

Read article
Transform Data into Type-safe DTOs with this PHP Package image

Transform Data into Type-safe DTOs with this PHP Package

Read article
PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell image

PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell

Read article
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article