Laravel 7.4 Released

Laravel 7.4 Released

The Laravel team released v7.4.0 yesterday with quite a few new features, such as a custom model caster interface, a “when” higher-order collection proxy, and the ability to clear an existing “order” from the query builder:

Higher Order “when” Proxy for Collections

Loris Leiva contributed the ability to use a higher-order proxy with the Collection::when() method:

// With this PR, this:
$collection->when($condition, function ($collection) use ($item) {

// ... can be refactored as this:

This PR enables you to chain other higher-order proxy methods:

// This:
$collection->when($condition, function ($collection) {

// ... can be refactored as this:

Artisan expectsChoice() Assertion

Adrian N├╝rnberger contributed a console test method for asking choices.

Given the following example:

$name = $this->choice('What is your name?', ['Taylor', 'Dayle'], $defaultIndex);

You could only assert the message of this question, but cannot test the given choices:

  ->expectsQuestion('What is your name?', 'Taylor')

As of Laravel 7.4, you can now do the following:

  ->expectsChoice('What is your name?', 'Taylor', ['Taylor', 'Dayle'])

You can also guarantee the order of choices by passing a fourth boolean argument:

  ->expectsChoice('What is your name?', 'Taylor', ['Taylor', 'Dayle'], true)

Default Values for the @props Blade Tag

@nihilsen contributed the ability to define default props via @props:

<!-- Previously you might need something like: -->
@props(['type', 'message'])
    $type = $type ?? 'info'

<!-- New defaults in Laravel >=7.4 -->
@props(['type' => 'info', 'message'])

Castable Interface

Brent Roose contributed a Castable interface which allows “castable” types to specify their caster classes:

// Instead of this
class ModelX extends Model
    protected $casts = [
        'data' => CastToDTO::class . ':' . MyDTO::class,

// You could do this
class ModelY extends Model
    protected $casts = [
        'data' => MyDTO::class,

// The underlying class
use Illuminate\Contracts\Database\Eloquent\Castable;

class MyDTO implements Castable
    public static function castUsing()
        return CastToDTO::class . ':' . static::class;

Remove Orders from the Query Builder

Jonathan Reinink contributed a reorder() method to the query builder to reset orderBy() calls:

$query = DB::table('users')->orderBy('name');

$unorderedUsers = $query->reorder()->get();

Reorder allows you to define default order in Eloquent relationships, with the ability to back out if needed:

class Account extends Model
    public function users()
        return $this->hasMany(User::class)->orderBy('name');

// Remove the name orderBy and order by email

// The same can be written as:

Release Notes

You can see the full list of new features and updates below and the diff between 7.3.0 and 7.4.0 on GitHub. The full release notes for Laravel 7.x are available in the latest v7 changelog:



  • Makes the stubs used for make:policy customizable (#32040, 9d36a36)
  • Implement HigherOrderWhenProxy for Collections (#32148)
  • Added Illuminate\Testing\PendingCommand::expectsChoice() (#32139)
  • Added support for default values for the “props” blade tag (#32177)
  • Added Castable interface (#32129, 9cbf908, 651371a)
  • Added the ability to remove orders from the query builder (#32186)


  • Added missing return in the PendingMailFake::sendNow() and PendingMailFake::send() (#32093)
  • Fixed custom Model attributes casts (#32118)
  • Fixed route group prefixing (#32135, 870efef)
  • Fixed component class view reference (#32132)


  • Remove Swift Mailer bindings (#32165)
  • Publish console stub when running stub:publish command (#32096)
  • Publish rule stub when running make:rule command (#32097)
  • Adding the middleware.stub to the files that will be published when running php artisan stub:publish (#32099)
  • Adding the factory.stub to the files that will be published when running php artisan stub:publish (#32100)
  • Adding the seeder.stub to the files that will be published when running php artisan stub:publish (#32122)

Filed in: News / Laravel 7 / Releases


Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Full Stack PHP (Mid-Level/Senior) Programmer
Software Developer
Remote, (US & Canada Only)
Patient Prism
Web Application Developer
Chicago Loop
Leading Real Estate Companies of the World
Multiple Laravel Developers (Part-Time)
Remote, USA Only
The Great Escape Room
Software Developer
Remote (US & Canada)