Cancel Pending Notifications Immediately in Laravel 8.50


July 14th, 2021


The Laravel team released v8.50.0 this week with the ability to cancel pending notifications, "pruneable" models, commonmark v2 support, and the latest changes in the 8.x branch:

Cancel Notifications

Graham Bradley contributed the ability to cancel notifications immediately before sending. To determine if a notification should be sent, you can now conveniently add custom logic around your notification class using the shouldSend method:

1public function shouldSend($notifiable, $channel)
3 // custom logic
4 return true;

I'd encourage you to check out the pull request description for further details on what this accomplishes.

Prunable Models

Nuno Maduro contributed a way to remove obsolete records by making Laravel models "prunable":

When making models prunable, Laravel will automatically remove obsolete model records from the database via a scheduled command.

Here's an example of a prunable model from the pull request's description:

1namespace App\Models;
3use Illuminate\Database\Eloquent\Model;
4use Illuminate\Database\Eloquent\Prunable; // or MassPrunable
6class Post extends Model
8 use Prunable; // or MassPrunable
10 /**
11 * Determines the prunable query.
12 *
13 * @return \Illuminate\Database\Eloquent\Builder
14 */
15 public function prunable()
16 {
17 return $this->where('created_at', '<=', now()->subMonth());
18 }

Coupled with a scheduled task of running artisan model:prune, Laravel will automatically detect prunable support and keep database records tidy. Pull Request #37889 has excellent details on how model pruning works.

Commonmark V2 Support

Colin O'Dell contributed support for both Commonmark v1 and v2. With the upcoming commonmark release, users of Laravel 8.x can install either major version of the CommonMark library.

Exclude Array Keys Not Included In Validation Rules

Mohamed Said contributed an opt-in method you can add to a service provider that will exclude array keys not included in validation rules:

1// In a service provider
4// Will not return keys without validation rules
5// For example, users.*.email would not be returned (if "email" were a key)
7 'users' => 'required|array',
8 'users.*.name' => 'required',

Since this is potentially a breaking change, this feature is opt-in in Laravel 8.

Release Notes

You can see the full list of new features and updates below and the diff between 8.49.0 and 8.50.0 on GitHub. The following release notes are directly from the changelog



  • Added ability to cancel notifications immediately prior to sending (#37930)
  • Added the possibility of having "Prunable" models (#37889)
  • Added support for both CommonMark 1.x and 2.x (#37954)
  • Added Illuminate/Validation/Factory::excludeUnvalidatedArrayKeys() (#37943)


  • Fixed Illuminate/Bus/PendingBatch::add() (108385b)
  • Cursor pagination fixes (#37915)


  • Mixed orders in cursor paginate (#37762)
  • Clear config after dumping auto-loaded files (#37985)

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.