Laravel 9.48 Released

Published on by

Laravel 9.48 Released image

The Laravel team released 9.48 this week with conditional fragment helpers, HTTP configuration options for Symfony mailers, a new DB schema helper, and more:

DB Schema helper to toggle foreign key constraints

Patrick Hesselberg contributed a withoutForeignKeyConstraints Schema method to conveniently disable foreign key constraints while managing a DB schema:

// Before
Schema::disableForeignKeyConstraints();
Schema::dropIfExists('table1');
Schema::dropIfExists('table2');
Schema::enableForeignKeyConstraints();
 
// After
Schema::withoutForeignKeyConstraints(function () {
Schema::dropIfExists('table1');
Schema::dropIfExists('table2');
});

New fragment helpers

Arko Elsenaar contributed a fragmentIf() method to return a fragment of a view conditionally. Sending a fragment is useful when sending a partial HTML view over the wire in XHR requests, for example:

// Before
if (request()->hasHeader('HX-Request')) {
return view('products.index')->fragment('products-list');
}
 
return view('products.index');
 
// After
return view('products.index')
->fragmentIf(
request()->hasHeader('HX-Request'),
'products-list'
);

Arko also contributed a fragments() method to return multiple fragments conveniently:

// Before using concatenation
view('welcome')->fragment('fragment1') . view('welcome')->fragment('fragment2');
 
// After
view('welcome')->fragments(['fragment1', 'fragment2']);

Building on Arko's first PR, the fragmentIf() has an accompanying fragmentsIf() method to conditionally render an array of fragments:

view('welcome')
->fragmentsIf(
request()->hasHeader('HX-Request'),
['fragment1', 'fragment2']
);

Increment each query builder method

Iman contributed an incrementEach() method to increment multiple columns with a single query atomically:

DB::table('products')->where('id', 2)->incrementEach([
'in_store' => 2,
'in_stock' => 3,
'total' => 5,
], ['updated_at' => now()]);

Drop an index when modifying a column

Hafez Divandari contributed the ability to drop an index by its conventional name when modifying a column by passing false to unique:

$table->string('name')->unique(false)->change();

Configure custom HTTP client options for mailers

Dries Vints contributed the configuration of custom HTTP client options for Symfony's Postmark and Mailgun mailers:

'mailgun' => [
'transport' => 'mailgun',
'client' => [
'timeout' => 7.5 // Seconds
],
],

You can find the configuration options referenced in the Symfony Docs.

402 status code exception view

Zep Fietje contributed an exception view for the nonstandard 402 status code:

Currently no error page exists for exceptions with an HTTP status code of 402 Payment Required.

Even though it's a nonstandard response status code , it's used by multiple large companies to indicate functionality limited due to a payment being required.

HTTP client "notFound()" response helper

Erik Gaal contributed a notFound() HTTP client response helper that provides a convenience around checking for a 404 response:

$response = Http::get('https://laravel.com');
 
// Checking the status code
if ($response->status() === 404) {
doSomething();
}
 
// New helper method
if ($response->notFound()) {
doSomething();
}

Release Notes

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

v9.48.0

Added

  • Added Illuminate/Database/Schema/Builder::withoutForeignKeyConstraints() (#45601)
  • Added fragments() \ fragmentIf() \ fragmentsIf() methods to Illuminate/View/View.php class (#45656, #45669)
  • Added incrementEach() and decrementEach() to Illuminate/Database/Query/Builder (#45577)
  • Added ability to drop an index when modifying a column (#45513)
  • Allow to set HTTP client for mailers (#45684)
  • Added 402 exception view (#45682)
  • Added notFound() helper to Http Client response (#45681)

Fixed

Changed

  • Ignore whitespaces/newlines when finding relations in model:show command (#45608)
  • Fail queued job with a string messag (#45625)
  • Allow fake() helper in unit tests (#45624)
  • allow egulias/email-validator v4 (#45649)
  • Force countBy method in EloquentCollection to return base collection (#45663)
  • Allow for the collection of stubs to be published (#45653)
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
Laravel Idea for PhpStorm logo

Laravel Idea for PhpStorm

Ultimate PhpStorm plugin for Laravel developers, delivering lightning-fast code completion, intelligent navigation, and powerful generation tools to supercharge productivity.

Laravel Idea for PhpStorm
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
JetShip - Laravel Starter Kit logo

JetShip - Laravel Starter Kit

A Laravel SaaS Boilerplate and a starter kit built on the TALL stack. It includes authentication, payments, admin panels, and more. Launch scalable apps fast with clean code, seamless deployment, and custom branding.

JetShip - Laravel Starter Kit
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 →
Handling Geospatial Data with Laravel Magellan image

Handling Geospatial Data with Laravel Magellan

Read article
Managing Large Datasets in Laravel with LazyCollection image

Managing Large Datasets in Laravel with LazyCollection

Read article
Collect and Monitor Everything About Sent Emails in Your Laravel App image

Collect and Monitor Everything About Sent Emails in Your Laravel App

Read article
Packagist.org is ending support for Composer 1.x image

Packagist.org is ending support for Composer 1.x

Read article
Mastering Dynamic String Manipulation with Laravel's Str::replaceArray() image

Mastering Dynamic String Manipulation with Laravel's Str::replaceArray()

Read article
Laravel Jobs - December image

Laravel Jobs - December

Read article