Laravel custom messages for array validation

后端 未结 10 2444
南笙
南笙 2021-02-20 05:36

I am having a form and I have an array of input fields for video urls, now when I validate form if I have multiple invalid fields with video urls, I get the same message for eac

10条回答
  •  你的背包
    2021-02-20 06:18

    You can use as

    $messages = [
        'title.required' => 'Du må ha tittel.',
        'type.required' => 'Du må velge artikkeltype.',
        'category.required' => 'Du må velge kategori.',
        'summary.required' => 'Du må ha inngress.',
        'text.required' => 'Du må ha artikkeltekst.',
        'active_url' => 'Du må ha gyldig url.',
    ];
    
    $validator = Validator::make($data, [
        'external_media.*' => 'active_url',
        'title' => 'required',
        'type' => 'required',
        'category' => 'required',
        'summary' => 'required',
        'text' => 'required',
        //'image' => 'required|image|max:20000'
    ], $messages);
    
    if ($validator->fails()){
        // handle validation error
    } else {
        // no validation error found
    }
    

提交回复
热议问题