inertia
inertia copied to clipboard
Determining InertiaJs
Versions:
@inertiajs/inertiaversion: v0.6.3
Describe the problem:
I created a General Exception, it should determine if it is an axios request or inertiajs..
so what will happen is if it is an axios request it will just return a response()->json() but if it is an intertia request
it should return redirect()->back()
Steps to reproduce:
$request->ajax() is true for axios and inertia request
I think i got it.. i used $request->headers->get('x-inertia') to check the request
I also did something like that, maybe there's a better way...but it works :)
if (request()->header('X-Inertia')) {
return redirect()->back();
}
return response()->json([
// .... json response here
]);
This should've really been asked on the Laravel adapter repo, as that's where you'll also find the code to actually check server-side if the request was an Inertia request: https://github.com/inertiajs/inertia-laravel/blob/master/src/ServiceProvider.php#L73-L75
So, you can just use $request->inertia()
Thank you so much!
Hey! Thanks so much for your interest in Inertia.js and for sharing this issue/suggestion.
In an attempt to get on top of the issues and pull requests on this project I am going through all the older issues and PRs and closing them, as there's a decent chance that they have since been resolved or are simply not relevant any longer. My hope is that with a "clean slate" me and the other project maintainers will be able to better keep on top of issues and PRs moving forward.
Of course there's a chance that this issue is still relevant, and if that's the case feel free to simply submit a new issue. The only thing I ask is that you please include a super minimal reproduction of the issue as a Git repo. This makes it much easier for us to reproduce things on our end and ultimately fix it.
Really not trying to be dismissive here, I just need to find a way to get this project back into a state that I am able to maintain it. Hope that makes sense! ❤️