Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 ?

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda