Laravel 10.43 Introduces Streamed JSON Responses

The Laravel team has once again delivered a powerful update with version 10.43, introducing several noteworthy features and improvements. This version packs enhancements that cater to the needs of developers, making Laravel even more robust and versatile.
This now supports assigning a class name to register a global eloquent scope, a new insertOrIgnoreUsing Eloquent method.
Let’s delve into the key highlights of Laravel 10.43
1. Support for Streamed JSON Responses
In Symphony 6.3, the StreamedJsonResponse was introduced, which offers a solution for handling large data payloads more efficiently by reducing memory usage.
Example usage in a controller:
namespace App\Http\Controllers;
use Generator;
use App\Models\User;
class ExampleController extends Controller
{
public function index()
{
return response()->streamJson([
'users' => $this->yieldUsers(),
]);
}
protected function yieldUsers(): Generator
{
foreach (User::query()->cursor() as $user) {
yield $user;
}
}
}
Additionally, a new test helper is introduced to assert streamed JSON content:
$response->assertStreamedJsonContent([
'data' => [
['id' => 11],
['id' => 12],
['id' => 13],
],
]);The main benefits of streamed responses are that it uses a lot less memory and can be a lot faster, especially for very large responses. You can yield data that flushes straight into the response stream and the client can start to process the data before all the data is ready and sent on the server side.
You can learn more about this Symphony feature from their HttpFoundation Component documentation for Streaming a JSON Response.
2. New Eloquent insertOrIgnoreUsing Method
Let’s talk about the new insertOrIgnoreUsing method for Eloquent, facilitating bulk insert using a sub-select. This method succeeds even if key conflicts occur, specifically designed for connectors supporting the 'ignore' functionality.
Example usage
$result = $builder->from('table1')->insertOrIgnoreUsing(
['foo'],
function (Builder $query) {
$query->select(['bar'])->from('table2')->where('foreign_id', '=', 5);
}
);
// MySQL:
// insert ignore into `table1` (`foo`) select `bar` from `table2` where `foreign_id` = ?'// MySQL: insert ignore into `table1` (`foo`) select `bar` from `table2` where `foreign_id` = ?'3. New Schema hasIndex() Method
The new Schema::hasIndex() method along with other methods allows for convenient operations related to indexes.
Usage examples include checking for an index, listing tables, and getting index listings.
Schema::hasIndex('users', 'my_index_name');
Schema::hasIndex('users', ['email']);
Schema::hasIndex('users', ['email'], 'unique');
// ... and more
Schema::getTableListing(); // string[]
Schema::getIndexListing('users'); // string[]4. Use Class Names When Adding Global Scopes
Now, you can pass a scope class name when adding a global scope to a model. This provides a cleaner and more organized approach to managing global scopes.
Example
protected static function booted(): void
{
static::addGlobalScope(AncientScope::class);
}Also, the introduction of addGlobalScopes() method, enables the registration of multiple global scopes at once.
protected static function booted(): void
{
static::addGlobalScopes([FirstScope::class, SecondScope::class]);
}5. New Artisan Command: storage:unlink
Here is a handy Artisan command:
php artisan storage:unlinkThis command efficiently deletes all symbolic links, providing a straightforward solution for managing storage links.
Release notes
You can see the complete list of new features and updates below and the diff between 10.42.0 and 10.43.0 on GitHub. The following release notes are directly from the changelog:
Conclusion
Laravel 10.43 enhances the development experience with these impactful features and improvements. Whether you are dealing with large data payloads, managing indexes, or utilizing global scopes, Laravel continues to provide elegant solutions. Now, you can explore the complete list of updates and features on GitHub.





