Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

laraveil's avatar

Problem with Laravel + Inertia when validating request

Hi all, I'm currently working on a project started by someone else which uses Laravel (8.55.33) + Jetstream + Inertia + Vue. I'm currently having an issue when the request fails due to validation.

In the view, the form is created with this.$inertia.form({...}) and submitted with this.form.put()

In the controller I have code like this:

public function update(Request $request, $id)
{
    $data = $request->validate([...]);
    // actions with $data
	return back(303);
}

If the request is valid, everything seems to work fine: I see in the requests tab an HTTP put request with a 303 response which then triggers an additional GET on the resource. However, if the request fails the validation rules, the inertia request get an 409 status code with then redirects the user to the home page. Why is that and how can I solve it?

0 likes
10 replies
laraveil's avatar

@vincent15000 Yes

this.form.put(route('update', this.id), {
  preserveScroll: true,
  onSuccess: (page) => {
    // actions
  },
  onError: (errors) => {
    this.showError(errors[0])
  }
})

also, the response with HTTP status 409 does not have a body.

vincent15000's avatar

@Sinnbeck About the error handling ... or the version handling ... I don't understand why it's interesting for his problem.

laraveil's avatar

@Sinnbeck Thanks, it seems that was the problem! There's some weird code in the render method:

$response = parent::render($request, $e);

if ($request->hasHeader('X-Inertia')) {
    if (in_array($response->status(), [302])) {
        return Inertia::location(route('login'));
    } elseif (!app()->environment('local'))  {
        return back(303)->withErrors($this->responseStatusMessage($response->status()));
    }
}

return $response;

If changing to default implementation the behavior changes. I'll try to understand the motivation for this code and fix it accordingly. Thanks again!

1 like
Sinnbeck's avatar

@vincent15000 if the exception handling catches all validation errors and does weird things

Or versioning. If I recall correctly inertia does a 409 response on new assets which tells the browser to reload everything. So setting it to return true, could give issues

1 like
Sinnbeck's avatar

@vincent15000 I hardly ever notice. I mostly just take the threads I find interesting. If you want my attention it might be easier sending me a dm on Twitter :)

1 like

Please or to participate in this conversation.