Laravel 9.35 Released

Published on by

Laravel 9.35 Released image

The Laravel team released 9.35 with an exciting new alternate mailable syntax, an Eloquent "strict mode" feature, and more.

Alternate mailable syntax

Taylor Otwell contributed an alternate mailable syntax to works by returning "slim value objects that specify the content and attributes of the mailable"

Here's an example from his pull request description:

namespace App\Mail;
 
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
 
class InvoicePaid extends Mailable
{
use Queueable, SerializesModels;
 
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
 
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
subject: 'Invoice Paid',
cc: [new Address('foo@example.com', 'Example Name')],
tags: [],
metadata: [],
);
}
 
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
view: 'html-view-name',
text: 'text-view-name',
);
}
 
/**
* Get the attachments for the message.
*
* @return \Illuminate\Mail\Mailables\Attachment[]
*/
public function attachments()
{
return [
Attachment::fromPath('/path/to/file'),
];
}
}

The traditional way of defining mailables using build() will not be removed. I like how the above example is obvious what is happening using PHP 8's named arguments.

Eloquent "strict" mode

Chris Morrell and Taylor Otwell collaborated on an Eloquent strict mode, which enables the following:

  • No lazy loading
  • Exceptions when assigning non-fillable attributes
  • Exceptions accessing attributes that weren't retrieved or didn't exist

Ideally, you'll use strict mode in development by adding the following to the boot() method of a registered service provider:

Model::shouldBeStrict();

The shouldBeStrict() method is a shortcut for enabling all of the following:

Model::preventLazyLoading();
Model::preventSilentlyDiscardingAttributes();
Model::preventsAccessingMissingAttributes();

Load trashed models with resource routes

Andrew Brown contributed the ability to load trashed models with resource routes using the following routing syntax:

// All endpoints
Route::resource('users', UserController::class)->withTrashed();
 
// Only `show`
Route::resource('users', UserController::class)->withTrashed(['show']);

Release Notes

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

v9.35.0

Added

  • Allow loading trashed models for resource routes (#44405)
  • Added Illuminate/Database/Eloquent/Model::shouldBeStrict() and other (#44283)
  • Controller middleware without resolving controller (#44516)
  • Alternative Mailable Syntax (#44462)

Fixed

  • Fix issue with aggregates (withSum, etc.) for pivot columns on self-referencing many-to-many relations (#44286)
  • Fixes issue using static class properties as blade attributes (#44473)
  • Traversable should have priority over JsonSerializable in EnumerateValues (#44456)
  • Fixed make:cast --inbound so it's a boolean option, not value (#44505)

Changed

  • Testing methods. Making error messages with json_encode more readable (#44397)
  • Have 'Model::withoutTimestamps()' return the callback's return value (#44457)
  • only load trashed models on relevant routes (#44478)
  • Adding additional PHP extensions to shouldBlockPhpUpload Function (#44512)
  • Register cutInternals casters for particularly noisy objects (#44514)
  • Use get methods to access application locale (#44521)
  • return only on non empty response from channels (09d53ee, 3944a3e)
  • Correct channel matching (#44531)
  • Migrate mail components (#44527)
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
No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project.

Visit No Compromises
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

Bespoke software solutions built for your business. We ♥ Laravel

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
All Green logo

All Green

All Green is a SaaS test runner that can execute your whole Laravel test suite in mere seconds so that you don't get blocked – you get feedback almost instantly and you can deploy to production very quickly.

All Green
Larafast: Laravel SaaS Starter Kit logo

Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes. Available with VILT and TALL stacks.

Larafast: Laravel SaaS Starter Kit
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a 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
Rector logo

Rector

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

Rector

The latest

View all →
Property Hooks Get Closer to Becoming a Reality in PHP 8.4 image

Property Hooks Get Closer to Becoming a Reality in PHP 8.4

Read article
Asserting Exceptions in Laravel Tests image

Asserting Exceptions in Laravel Tests

Read article
Reversible Form Prompts and a New Exceptions Facade in Laravel 11.4 image

Reversible Form Prompts and a New Exceptions Facade in Laravel 11.4

Read article
Basset is an alternative way to load CSS & JS assets image

Basset is an alternative way to load CSS & JS assets

Read article
Integrate Laravel with Stripe Connect Using This Package image

Integrate Laravel with Stripe Connect Using This Package

Read article
The Random package generates cryptographically secure random values image

The Random package generates cryptographically secure random values

Read article