inertia-laravel
inertia-laravel copied to clipboard
feat: add X-Inertia-Include-Data header
This PR will support a new header called X-Inertia-Include-Data which allows users to explicitly request lazy data. If you think that this is a good idea we could not only check the header but also a specific key within the session (that was set with flash).
My specific use case is this:
- Page loads without lazy data
- User clicks on a button and lazy data is loaded (via
reload) - User submits form that triggers a controller method that redirects
back - Inertia replaces previously loaded lazy data with undefined because it's lazy and thus ignored in the new request
My idea would be to use the back method but flash some data:
back(303)->flash('Inertia-Include-Data', 'lazyDataKey');
and use a custom middleware:
$request->headers->set('X-Inertia-Include-Data', ($request->header('X-Inertia-Include-Data') ?? '') . ',' . (Session::get('Inertia-Include-Data') ?? ''), true);
Ideally, we could also create an Inertia helper that would do this magically:
Inertia::back()->include('lazyDataKey');
What do you think? Or is this use case considered somehow else?