3 months ago

Laravel validation type depending on request ?

Posted 3 months ago by Atef95

Hey artisans

I have the following rules that I'm using to validate uploaded files during submission ( mutli languages)

'file_en_withoutbackground' => 'bail|required_without_all:file_ar_withoutbackground,file_fr_withoutbackground|mimes:mpga,wav|nullable',
            'file_fr_withoutbackground' => 'bail|required_without_all:file_ar_withoutbackground,file_en_withoutbackground|mimes:mpga,wav|nullable',
            'file_ar_withoutbackground' => 'bail|required_without_all:file_en_withoutbackground,file_fr_withoutbackground|mimes:mpga,wav|nullable',

it works properly in case of insertion

whereas for the update , if the file already exists I'm passing the path instead..

so I get this error below

 must be a file of type: mpga, wav.

is there a way that I can specify a rule depending on the upcoming value ?

so it could be string instead of mimes in case it's a path ?

Thank you!

Please sign in or create an account to participate in this conversation.