Laravel custom messages for array validation

后端 未结 10 2445
南笙
南笙 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:03

    public function messages() {
    
        $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.',
    
        ];
    
        foreach ($this->get('external_media') as $key => $val) {
            $messages["external_media.$key.active_url"] = "$val is not a valid active url";
        }
    
        return $messages;
    
    }
    

提交回复
热议问题