Heartbeat Collection Method in Laravel 12.26; Wayfinder Now in React and Vue Starter Kits
Last updated on by Paul Redmond
Never Miss a Laravel Release 🚀
The Laravel team released version 12.26.0, adding a withHeartbeat() method to Lazy collections, a toPrettyJson() method to collections, models, and more. Additionally, the Laravel Vue and React starter kits include Wayfinder, which bridges type-safe routes between Laravel and your frontend.
React and Vue Starter Kits Now Include Wayfinder
Joe Tannenbaum updated the Laravel React and Vue Starter Kits to include Laravel Wayfinder. Wayfinder provides a type-safe bridge between your Laravel routes and frontend:
import { store, update } from "@/actions/App/Http/Controllers/PostController"; const Page = () => ( <form {...update.form.put(1)}> {/* <form action="/posts/1?_method=PUT" method="post"> */} {/* ... */} </form>);
Add withHeartbeat() Method to LazyCollection
Joseph Silber contributed a new withHeartbeat() method to LazyCollection, which allows you to run a callback at regular intervals while the collection is being lazily enumerated. Joseph shared the primary use-case for this method in Pull Request #56477:
In long-running tasks such as batch processing reports, you may need to hold a lock to prevent concurrent execution. However, if the code unexpectedly fails to release the lock, you don't want it to persist indefinitely. A common strategy is to acquire a short-lived lock, and then periodically extend it while the task is still running.
Here's an example where we acquire a lock for 5 minutes, then reacquire it every 4 minutes (assuming a report never takes a full minute to generate):
$lock = Cache::lock('generate-reports', CarbonInterval::minutes(5)); $lock->acquire(); Reports::where('status', 'pending') ->lazy() ->withHeartbeat(CarbonInterval::minutes(4), $lock->reacquire(...)) ->each($this->generateReport(...)); $lock->release();
The collections documentation has been updated, including a section about the withHeartbeat() method.
Pretty JSON Method
Wendell Adriel contributed a toPrettyJson() method, implemented in most places where the toJson() method exists. For example, collections, models, JSON resources, paginators, Fluent instances, and message bags. Here's an example from Pull Request #56697 using collections:
// Before$collection = collect([1,2,3]);$collection->toJson(JSON_PRETTY_PRINT); // After$collection = collect([1,2,3]);$collection->toPrettyJson();
Release notes
You can see the complete list of new features and updates below and the diff between 12.25.0 and 12.26.0 on GitHub. The following release notes are directly from the changelog:
v12.26.0
- [12.x] feat: add native return types to helper functions by @calebdw in https://github.com/laravel/framework/pull/56684
- [12.x] Allow passing enum to
Databaseattribute by @jnoordsij in https://github.com/laravel/framework/pull/56688 - [12.x] Clean up redundant type hints in docblocks by @amirhshokri in https://github.com/laravel/framework/pull/56690
- Add ability to specify a transaction mode for SQLite connection by @panda-madness in https://github.com/laravel/framework/pull/56681
- [12.x] Fix
spliceIntoPositiondocblock to allowstring|intvalues by @amirhshokri in https://github.com/laravel/framework/pull/56698 - [12.x] Use array_first and array_last polyfills by @KIKOmanasijev in https://github.com/laravel/framework/pull/56703
- [12.x] Fix path to Str in exception markdown by @apreiml in https://github.com/laravel/framework/pull/56705
- [12.x] Add
withHeartbeatmethod toLazyCollectionby @JosephSilber in https://github.com/laravel/framework/pull/56477 - [12.x] Add toPrettyJson method by @WendellAdriel in https://github.com/laravel/framework/pull/56697
- [12.x] Use
array_firstandarray_lastby @KIKOmanasijev in https://github.com/laravel/framework/pull/56706 - [12.x] Do not dispatch
MessageLoggedtwice by @cosmastech in https://github.com/laravel/framework/pull/56713 - [12.x] Order classes alphabetically by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/56743
- [12.x] Normalize file path separators for commands on Windows by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/56734
- [12.x] Improve
queue:prune-failedtests coverage by @amirhshokri in https://github.com/laravel/framework/pull/56732 - [12.x] Align trait usage for consistency by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/56727
- [12.x] Fix composer suggests for illuminate/container by @cosmastech in https://github.com/laravel/framework/pull/56722
- Add nullableTimestampsTz method to Blueprint by @mohamedhabibwork in https://github.com/laravel/framework/pull/56720
- Add possibility to override symbol when using currency format by @PhilippeThouvenot in https://github.com/laravel/framework/pull/56749
- [12.x] Revert #56608 by @amirhshokri in https://github.com/laravel/framework/pull/56752
- Revert "Add possibility to override symbol when using currency format" by @taylorotwell in https://github.com/laravel/framework/pull/56753
- [12.x] Support
nullparameter inBusFake::chain()method by @stevebauman in https://github.com/laravel/framework/pull/56750 - [12.x] Remove unnecessary return in ddBody for consistency by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/56759
- [12.x] Make interface accept UnitEnum by @parijke in https://github.com/laravel/framework/pull/56758
- [12.x] Fix concurrency closure invocation: use base64 encoding by @sashko-guz in https://github.com/laravel/framework/pull/56757
- [12.x]
ArrayStore::all()by @cosmastech in https://github.com/laravel/framework/pull/56751 - [12.x] Fix: Add
$forceWrapproperty to JsonResource for consistent API response #56724 by @achrafAa in https://github.com/laravel/framework/pull/56736 - [12.x] Ensures casts objects can be transformed into strings by @DarkGhostHunter in https://github.com/laravel/framework/pull/56687