The validation sends automatically the errors if the request is not validated.
Have a look at the response, you will find the errors inside it.
if (!res.ok) {
console.log(res)
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
my store api controller method
public function register(Request $request)
{
$attributes = $request->validate([
'name' => 'required',
'email' => 'required|unique:users,email',
'password' => 'required|confirmed',
]);
$user = User::create($attributes);
return response()->json([
'username' => $user->name
]);
}
my store
import { defineStore } from 'pinia'
export const useAuthStore = defineStore('auth', {
state: () => ({
user: '',
token: '',
}),
actions: {
async registerUser(formData) {
try {
const res = await fetch('http://127.0.0.1:8000/api', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData),
})
if (!res.ok) {
console.log('Error occured')
} else {
const data = await res.json()
console.log(data)
}
} catch (error) {
console.log(`Error during registration ${error}`)
}
},
},
getters: {},
})
my register method
and getting this
CORS error in network tab not any preview or anything.
how to get those validaton error ?
Please or to participate in this conversation.