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

anjanesh's avatar

Clarification on inner workings on inertia middleware

Trying https://github.com/piotr-jura-udemy/master-laravel-vue-fullstack

App/Http/Controllers/AuthController.php

public function store(Request $request)
{
    if (!Auth::attempt($request->validate([
        'email' => 'required|string|email',
        'password' => 'required|string'
    ]), true)) {
        throw ValidationException::withMessages([
            'email' => 'Authentication failed'
        ]);
    }

    $request->session()->regenerate();

    return redirect()->intended('/listing');
}

resources/js/Pages/Auth/Login.vue

<div v-if="form.errors.email" class="input-error">{{ form.errors.email }}</div>

<script setup>
import { useForm, Link } from '@inertiajs/inertia-vue3'
const form = useForm({
  email: null,
  password: null,
})
</script>    
  1. If $request->validate() or Auth::attempt() fail then when the exception is thrown it'll bubble down to the Inertia middleware where it gets 'caught' ?

  2. Inertia middleware sends in the data from PHP and populates to Vue automatically ?

0 likes
6 replies
CamKem's avatar

Are you asking how inertia interacts with Laravel to pass the serverside variable through the error bags to page props that are read by the vue components on the frontend in the browser?

I am interested in exact how this works too, if this is what you are asking.

1 like
Sinnbeck's avatar

Laravel already converts ValidationException to a proper validation error, and if the request is requesting json, it is converted to that. So Inertia simply builds on top of that

anjanesh's avatar

So basically the intertia adapter handles all this auto-magically ?

anjanesh's avatar

@Sinnbeck So $this->resolveValidationErrors($request); always returns a JSON if its in inertia and a regular PHP array if using blade ?

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@anjanesh No it is always converted to json. If its a request from javascript (router.get etc) it returns is as plain json, and if its a full page reload, it gets injected in the <div id="app"> as inline json

1 like

Please or to participate in this conversation.