Skip to content

Conversation

pascalbaljet
Copy link
Member

@pascalbaljet pascalbaljet commented Sep 2, 2025

This PR provides a new middle ground between Inertia::merge() and Inertia::deepMerge() so you can have fine-grained control over what should be merged.

In this example, the front-end will replace the entire object, except the data array. The new items will be appended to the existing items.

Inertia::merge(User::paginate())->append('data');

There's also prepend(), and you can also combine multiple calls.

Inertia::merge($complexObject)
    ->append('users', matchOn: 'username')
    ->prepend('messages.data');

You can pass arrays.

Inertia::merge($complexObject)->append(['users', 'messages']);

And even pass a key-value array where the key is the path, and the value the matchOn.

Inertia::merge($complexObject)->append([
    'users.data' => 'id',
    'messages' => 'uuid',
]);

Then there's a new Inertia::scroll() function which you can pass paginated resources.

Inertia::scroll(User::paginate());

In addition to automatically calling append('data') or prepend('data') for you, it sends normalized pagination metadata to the front-end, no matter if you use simple/cursor/full pagination, even wrapped within an Eloquent API resource.

Draft because the tests and front-end PR are not ready yet.

Fixes #762.
See also: inertiajs/inertia#2561

@pascalbaljet pascalbaljet changed the title More fine-grained control for Inertia::merge() and a new Inertia::paginate() More fine-grained control for Inertia::merge() and a new Inertia::scroll() Sep 3, 2025
@pascalbaljet pascalbaljet marked this pull request as ready for review September 3, 2025 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deepMerge() still replaces the data instead of merging it
1 participant