Laravel 8.81 Released

Published on by

Laravel 8.81 Released image

The Laravel team released 8.81 with a string scan method, the ability to disable caching in Attribute accessors, a getOrPut() collection method, and more:

Stringable Scan Method

Amir Rami contributed a scan method to stringable implemented using PHP's sscanf function:

$this->assertSame(
[123456],
$this->stringable('SN/123456')
->scan('SN/%d')
->toArray()
);
 
$this->assertSame(
['Otwell', 'Taylor'],
$this->stringable('Otwell, Taylor')
->scan('%[^,],%s')
->toArray()
);
 
$this->assertSame(
['filename', 'jpg'],
$this->stringable('filename.jpg')
->scan('%[^.].%s')
->toArray()
);

Disable Caching in Attribute Accessors

Declan Norton contributed to the ability to disable caching for attributes being accessed via the new Attribute class. You can use the new API in a few ways:

public function finish(): Attribute
{
return Attribute::getWithoutCaching(
fn () => $this->start->addSeconds($this->duration)
);
}
 
// or
 
public function finish(): Attribute
{
return Attribute::get(
fn () => $this->start->addSeconds($this->duration)
)->disableObjectCaching();
}

Here's an explanation of the use-case from the pull request's description:

I often find myself adding virtual accessors to construct objects based on other attributes within the model, most commonly DateTime instances.

Currently, the result of an accessor is cached if it's an object and only invalidated if the attribute's mutator is called. Scalar types are unaffected.

Get or Put Collection Method

@eusonlito contributed a getOrPut method to collections which simplifies the use-case where you either want to get an existing key or put the value if it doesn't exist and return the value:

// Still valid,
if ($this->collection->has($key) === false) {
$this->collection->put($key, $this->create($data));
}
 
return $this->collection->get($key);
 
// Using the `getOrPut()` method with closure
return $this->collection->getOrPut($key, fn () => $this->create($data));
 
// Or pass a fixed value
return $this->collection->getOrPut($key, $value);

Release Notes

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

v8.81.0

Added

  • Added Illuminate/Support/Stringable::scan() (#40472)
  • Allow caching to be disabled for virtual attributes accessors that return an object (#40519)
  • Added better bitwise operators support (#40529, def671d)
  • Added getOrPut on Collection (#40535)
  • Improve PhpRedis flushing (#40544)
  • Added Illuminate/Support/Str::flushCache() (#40620)

Fixed

  • Fixed Str::headline/Str::studly with unicode and add Str::ucsplit method (#40499)
  • Fixed forgetMailers with MailFake (#40495)
  • Pruning Models: Get the default path for the models from a method instead (#40539)
  • Fix flushdb for predis cluste (#40446)
  • Avoid undefined array key 0 error (#40571)

Changed

  • Allow whitespace in PDO dbname for PostgreSQL (#40483)
  • Allows authorizeResource method to receive arrays of models and parameters (#40516)
  • Inverse morphable type and id filter statements to prevent SQL errors (#40523)
  • Bump voku/portable-ascii to v1.6.1 (#40588, #40610)
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