Certainly! This is a common issue when using Inertia.js with Laravel validation. The root cause is usually that the controller is returning a standard Laravel redirect (which is for traditional web apps), rather than letting Inertia handle the error response.
The Problem
Your controller uses:
$request->validate([
'country_id' => 'required',
'state_id' => 'required'
]);
If validation fails, Laravel redirects back with errors (intended for Blade, not Inertia). Inertia expects a JSON response with a 422 status code for validation errors, so it can automatically bind errors to form.errors.
The Solution
Don't use $request->validate() in Inertia controllers.
Instead, use a Validator instance and manually throw the errors if validation fails:
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
public function register(Request $request)
{
$validator = Validator::make($request->all(), [
'country_id' => 'required',
'state_id' => 'required'
]);
if ($validator->fails()) {
throw new ValidationException($validator);
}
// ... your logic
return to_route('user.home')->with('success', 'Team registered successfully!');
}
This will cause Laravel to return a 422 JSON response with errors, which Inertia will automatically bind to your form.errors.
TL;DR
- Don't use
$request->validate()in Inertia controllers. - Use the Validator facade and throw
ValidationExceptionmanually.
Reference
Let me know if you need help displaying the errors in your Vue component!