Do you know Laravel have released version 9.47?

The Laravel team released 9.47 this week with new Eloquent collection visibility methods, “destroyable” singleton routes, support for lazy collections with the batch fake, and more。

Patrick Wan

--

laravel-new-release

There have 3 new updates for Laravel version 9.46.

1. New Eloquent collection visibility methods

2. Support lazy collections in BatchFake

3. “Destroyable” singleton routes

Let’s get in more detail.

Jess Archer contributed setVisible and setHidden methods to Eloquent collections. The setVisible method is useful when you want to be explicit about the data you want to return, and it won't leak as new attributes are added to the model:

$users->setVisible(['id', 'name'])->toArray();
/*
[
[
'id' => 1,
'name' => 'Test User',
]
]
*/

The converse setHidden is useful if you only have a few fields that you want explicitly hidden but generally want values visible by default.

Support lazy collections in BatchFake

Evan Burrell contributed support for LazyCollection when using the withFakeBatch() with a Job. The following now works thanks to this feature:

use Batchable;

Model::cursor()
->map(fn (Model $model) => new ModelJob($model))
->chunk(1000)
->each(function (LazyCollection $jobs) {
$this->batch->add($jobs);
});

// Associated test
[$job] = (new ModelJobBatch())->withFakeBatch();

$job->handle();

Learn more about mocking batches in the Mocking documentation.

“Destroyable” singleton routes

Choraimy Kroonstuiver contributed an easy way to mark singleton routes as “destroyable.” This type of route may be deleted, but it may not be created by default:

// Before
Route::singleton(...)->creatable()->except('create', 'store');

// After
Route::singleton(...)->destroyable();

Read more Laravel release articles:

--

--

Patrick Wan

My name’s Patrick. I’m a Software Developer, experience in Laravel, Vue Js, React Js, Livewire, Jquery, Codegniter, NPM, GIT. I have 5 years plus experience.