Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
next.js fetch data from Laravel

i am writing a simple user register using Laravel with a simple code

public function register()
{
    $this->validate(request(), [
        'name' => 'required',
        'email' => 'required|email|unique:users',
        'password' => 'required'
    ]);

    $user = User::create(request(['name', 'email', 'password']));
    
    auth()->login($user);

    return [
        'status' => true,
        'user' => $user
    ];
}

then i am sending the data form Next.Js :

using axios:

let config = {
    method: 'post',
    url: `http://localhost:8000/api/register`,
    headers: {
        'Content-Type': 'application/json',
    },
    data: values,
}
axios(config)
.then(json => console.log(json))

it's work fine, but i send an used email address, it will through 422 code, and axios can't catch the result

using fetch:

fetch('http://localhost:8000/api/register', {
    method: "post",
    mode: 'no-cors',
    body: new URLSearchParams(data)
}).then(res => res.json())
.then(json => console.log(json))

also work but when use used email, it will send 302 code , and call the index /

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think that you have missed adding the .catch(...) to return the error object like the example in docs Axios docs

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda