vendredi 7 septembre 2018

Laravel Validation: One required input that can come from either of two fields

So I have upload_media and url. upload_media is where you have to upload a .pdf file, and url if you want a url.

so what I want is that, if upload_media is not empty then, url should not be required. If the user decided to use the url, then the upload_media will not be required. But if either of them doesn't have a value then it should return a required error.

Here is my validation:

   $this->validate($request, [
        'title'              => 'required',
        'viewing_time'       => 'required',
        'tags'               => '',
        'description'        => '',
        'organization'       => '',
        'upload_media'       => '',
        'url'                => '',
        'upload_preview'     => 'required|file|image'
    ]);  



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire