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

160
Vistas
laravel validation messages by AJAX

I'm trying to get laravel error messages by ajax so that i can show it using sweet alert, till now i'm able to do it when i'm having the code in my controller like this :

// basic validation rules
$v = validator($request->all(), [
    'title' => 'required|min:1',
    'content' => 'required|min:2',
    'keywords' => 'required|min:1',
    'image_name' => 'required|image|mimes:jpeg,jpg,png,gif|max:20000',
        ], [
    'title.required' => Config::get('app.locale') == 'en' ? 'please enter a title' : 'برجاء ادخال العنوان',
    'title.min' => Config::get('app.locale') == 'en' ? 'title must be at least one word' : 'العنوان يجب الا يقل عن كلمه واحده ',
    'content.required' => Config::get('app.locale') == 'en' ? 'please enter a content' : 'برجاء ادخال المحتوي',
    'content.min' => Config::get('app.locale') == 'en' ? 'content must be at least two words' : 'المحتوي يجب ان يكون كلمتين عالاقل ',
    'keywords.required' => Config::get('app.locale') == 'en' ? 'please enter a keyword' : 'برجاء ادخال الكلمه الدلاليه',
    'keywords.min' => Config::get('app.locale') == 'en' ? 'please enter at least one keyword' : 'برجاء ادخال كلمه دلاليه واحده علااقل',
    'image_name.required' => Config::get('app.locale') == 'en' ? 'please select an image' : 'برجاء اختيار صوره ',
    'image_name.mimes' => Config::get('app.locale') == 'en' ? 'image type should be : jpeg,jpg,png,gif ' : 'نوع الصوره يجب ان يكون : jpeg,jpg,png,gif',
    'image_name.max' => Config::get('app.locale') == 'en' ? 'image must be smaller than 20MB' : 'الصوره يجب ان لا تزيد عن 20 ميجا بايت'
]);
// if the validation has been failed return the error msgs
if ($v->fails()) {
    return ['status' => false, 'data' => implode(PHP_EOL, $v->errors()->all())];
}

but when I move the messages to the request file it responses with 422 http status code and I can't get the response using ajax so can anyone help me to retrieve the response from the request file in ajax instead of using it in controller ?

over 4 years ago · Santiago Trujillo
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