News

JSON Unicode Cast Type Added in Laravel 12.3

Published
JSON Unicode Cast Type Added in Laravel 12.3 image

Release updates

Never miss a Laravel release

Get an email whenever a new Laravel release lands.

The Laravel team released v12.3.0, which includes a new JSON Unicode cast type, check linked storage status in the about command, native JSON and JSONB support in SQLite schemas, and more.

JSON Unicode Cast Type

@fuwasegu contributed a new json:unicode cast type for Eloquent attributes that allows JSON encoding with JSON_UNESCAPED_UNICODE:

protected $casts = [
'data' => 'json:unicode',
];

The Pull Request #54992 description explains when you might prefer this cast over the json cast:

This [cast] makes it easier to store and retrieve JSON data without Unicode escaping (\uXXXX), which is particularly useful for applications that handle non-ASCII characters like Japanese, Chinese, or emojis.

Currently, Eloquent's json cast escapes Unicode characters by default, making JSON-encoded attributes harder to read for humans and increasing the need for manual decoding. Developers often work around this by overriding accessors/mutators or manually using json_encode()...

Add "Storage Linked" Check to the about Command

Adam Patterson contributed a section to the artisan about command that shows the status of filesystems links. Given the following links in the filesystem.php configuration file:

// config/filesystem.php
return [
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('images') => storage_path('app/images'),
],
];

The artisan about command will show the status of these links:

$ php artisan about
 
Storage
public/images ................................................... NOT LINKED
public/storage .................................................. LINKED

Native JSON and JSONB Column Types in SQLite Schema

@fuwasegu contributed support for JSON and JSONB column types in SQLite schemas:

SQLite has supported JSON data type as a built-in feature since version 3.38.0, but prior to that, users needed to opt-in by installing an extension. Additionally, native support for JSONB type began with version 3.45.

Since Laravel 12 supports SQLite 3.26.0 and above, it should not be designed with the assumption that JSON/JSONB support is always available. While Query\Grammars\SQLiteGrammar includes support for JSON functions, Schema\Grammars\SQLiteGrammar does not offer this option. This Pull request allows injecting configuration from the database connection config to enable the use of native JSON columns when defining Schema.

Here are the configuration options:

'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
...,
'use_native_json' => true,
'use_native_jsonb' => true,
],

This pull request does not change the default, however, if you want to use native JSON or JSONB columns, you can enable these options in your connection. See Pull Request #54991 for implementation details and discussion.

Support for PostgreSQL "unique nulls not distinct"

Thierry Parent contributed support for PostgreSQL (>= 15) unique nulls not distinct when building unique indexes:

By adding support for a new nullsNotDistinct() fluent index definition method (see the unit tests for some examples) when using the postgres database driver (or more precisely when using the Postgres schema grammar).

Release notes

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

v12.3.0

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article