You get a redirect response when you send one from the back end:
return redirect()->route('login');
You also get a redirection if validation fails.
I am using laravel, inertia with vue.
In my network tab I am getting this
// 302 is post method ( I can also not see any errors into the form object)
register 302 xhr / Redirect Register.vue:51 1.2 kB 103 ms
register 200 xhr register
my controller
<?php
namespace App\Http\Controllers;
use App\Http\Requests\AuthenticationRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Inertia\Inertia;
class AuthenticationController extends Controller
{
public function register()
{
return Inertia::render('Auth/Register');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required|min:3|max:30|string',
"email" => 'required|email|unique:users,email',
'password' => 'required|min:8|max:20|confirmed'
]);
dd($request->all());
// $user = User::create([
// 'name' => $request->name,
// 'email' => $request->email,
// 'password' => $request->password,
// ]);
// session()->flash('success', 'Registered successfully!');
// return redirect()->route('login');
}
}
My register vue component
<template>
<div
class="fixed inset-0 flex justify-center items-center bg-gray-100 px-3"
>
<div
class="border shadow-md bg-white w-full md:w-[500px] px-6 py-10 rounded-lg"
>
<h2 class="text-black text-2xl text-center mb-6">Register Form</h2>
<form @submit.prevent="store">
<BaseInput
label="Name"
v-model="form.name"
:error="form.errors.name"
/>
<BaseInput
label="Email"
v-model="form.email"
:error="form.errors.email"
/>
<BaseInput
label="Password"
v-model="form.password"
:error="form.errors.password"
/>
<BaseInput
label="Confirm Password"
v-model="form.password_confirmation"
:error="form.errors.password_confirmation"
/>
<button class="text-black">Submit</button>
</form>
</div>
</div>
</template>
<script setup>
import BaseInput from "@components/Forms/BaseInput.vue";
import { useForm } from "@inertiajs/vue3";
const form = useForm({
name: "",
email: "",
password: "",
password_confirmation: "",
});
// register the user
function store() {
form.post("/register");
}
</script>
my routes
// register routes
Route::get('/register', [AuthenticationController::class, 'register'])->name('register');
Route::post('/register', [AuthenticationController::class, 'store'])->name('register.store');
Find the solution it was the inertia middle Handle inertia middleware it does not have the error flash messages sharing.
Please or to participate in this conversation.