Laravel Idea for PhpStorm - Full-featured IDE for productive artisans!

Laravel 9.4 Released

Published on by

Laravel 9.4 Released image

The Laravel team released 9.4 with the ability to override CSRF cookies, a Str::lcfirst() method, an optional retry mechanism for queued mailables, and more:

Allow VerifyCsrfToken’s CSRF cookie to be extended

@jaggy contributed the ability to override the VerifyCsrfToken by defining a newCookie method on an application’s extended CSRF middleware:

class VerifyCsrfToken extends Middleware {
protected function newCookie($request, $config)
{
return new Cookie(
"XSRF-TOKEN-{$request->user()->type}",
$request->session()->token(),
$this->availableAt(60 * $config['lifetime']),
$config['path'],
$config['domain'],
$config['secure'],
false,
false,
$config['same_site'] ?? null,
);
}
}

While most applications won’t need to override the default behavior, the PR author provides the following use-case:

There are some cases in multi-tenant systems that the user might want to change the CSRF token name to prevent 419 errors. Multiple Auth providers make this happen as well mainly in XHR requests. This also allows multi-tenant systems to update the token's domain (ie, pull the current tenant's custom domain) from the middleware layer.

I think this is going to help a lot with people using Inertia to allow customization in how XSRF-TOKEN is named by adding the tenant ID, or even the user type.

Add soleValue method to query builders

Matthew Hailwood contributed a new soleValue() method to query builders to return a column from the sole value instead of the whole record:

// bails if there is not exactly one result,
// but returns an object
$query->sole(['id']);
 
// returns just the value, but no safety around
// there being exactly one result
$query->value('id');
 
// To get the ID, we must do
$query->sole(['id'])->id;

This update allows the following usage:

// bails if there is not exactly one result,
// but returns an object
$query->sole(['id']);
 
// returns just the value, but no safety around
// there being exactly one result
$query->value('id');
 
// Bails if there is not exactly one result
// and returns just the value
$query->soleValue('id');

Add String lcfirst() Method

Vincent Prat contributed a lcfirst() method to the Str and Stringable classes, which also supports non-ASCII characters:

Str::lcfirst('Laravel'); // laravel
Str::lcfirst('Laravel framework'); // laravel framework
Str::lcfirst('Мама'); // мама
Str::lcfirst('Мама мыла раму'); // мама мыла раму

Add “Mutex” column to schedule:list command

@madman-81 contributed a Has Mutex column to the schedule:list command, indicating if a mutex blocks a command. Issue #41311 explains how this column can help debug any scheduler issues:

Today I ran into an issue with a scheduled task that wasn’t running. It took me a while to figure out was going on, mostly because the schedule:list showed nothing out of the ordinary and was updating the “Next Due” timestamp as expected. However the tasks wasn’t executed. Long story shot, the tasks got stuck because a mutex wasn’t cleared, probably because of an unscheduled server reboot.

Here’s an example of the output based outlined in the above issue:

$ php artisan schedule:list
+----------------------------------------------------------+-------------+--------------------+----------------------------+----------------------------+
| Command | Interval | Description | Next Due | Has Mutex |
+----------------------------------------------------------+-------------+--------------------+----------------------------+----------------------------+
| '/usr/bin/php8.0' 'artisan' mycommands:something | */2 * * * * | Process something | 2022-03-03 10:22:00 +00:00 | Yes |
| '/usr/bin/php8.0' 'artisan' mycommands:otherthing | */2 * * * * | Process otherthing | 2022-03-03 10:22:00 +00:00 | |
+----------------------------------------------------------+-------------+--------------------+----------------------------+----------------------------+

Support for Modifying a char Column Type

Hafez Divandari contributed the ability to modify a char column type:

Schema::table('users', function (Blueprint $table) {
$table->char('name', 50)->nullable()->change();
});

[The] doctrine/dbal package actually supports modifying char column types as StringType::class by setting fixed option to true.

So this PR, maps Laravel char to its Doctrine equivalent string type and set fixed option to true that finally gets the SQL snippet to declare a CHAR column .

Retry Mechanism for Queued Mailables

MaxGiting contributed the ability to specify a retryUntil() method or timeoutAt property to queued mailables. Check out Pull Request #41393 for more details.

Release Notes

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

v9.4.0

Added

  • Support modifying a char column type (#41320)
  • Add “Mutex” column to ‘schedule:list’ command (#41338)
  • Allow eloquent whereNot() and orWhereNot() to work on column and value (#41296)
  • Allow VerifyCsrfToken’s CSRF cookie to be extended (#41342)
  • Added soleValue() to query builder (#41368)
  • Added lcfirst() to Str and Stringable (#41384)
  • Added retryUntil method to queued mailables (#41393)

Fixed

  • Fixed middleware sorting for authenticating sessions (50b46db)
  • Fixed takeUntilTimeout method of LazyCollection (#41354, #41370)
  • Fixed directory for nested markdown files for mailables (#41366)
  • Prevent serializing default values of queued jobs (#41348)
  • Fixed get() and head() in Illuminate/Http/Client/PendingRequest.php (a54f481)

Changed

  • Don’t use global tap helper (#41326)
  • Allow chaining of Illuminate/Console/Concerns/InteractsWithIO::newLine (#41327)
  • set destinations since bcc missing from raw message in Mail SesTransport (8ca43f4)
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
Battle Ready Laravel

The ultimate guide to auditing, testing, fixing and improving your Laravel applications so you can build better apps faster and with more confidence.

Visit Battle Ready Laravel
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
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
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
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Join the Mastering Laravel community logo

Join the Mastering Laravel community

Connect with experienced developers in a friendly, noise-free environment. Get insights, share ideas, and find support for your coding challenges. Join us today and elevate your Laravel skills!

Join the Mastering Laravel community
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
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
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 →
Laravel Simple RabbitMQ Package image

Laravel Simple RabbitMQ Package

Read article
Navigating Dates Elegantly with Carbon in Laravel image

Navigating Dates Elegantly with Carbon in Laravel

Read article
Memoized Cache Driver in Laravel 12.9 image

Memoized Cache Driver in Laravel 12.9

Read article
Laravel Cookie Consent image

Laravel Cookie Consent

Read article
Converting Non-Decimal Strings with Laravel's Enhanced toInteger() Method image

Converting Non-Decimal Strings with Laravel's Enhanced toInteger() Method

Read article
Herd Xdebug Toggler for Visual Studio Code image

Herd Xdebug Toggler for Visual Studio Code

Read article