mercredi 31 octobre 2018

Laravel 5.7 validation rules

When I submit a form, this is what I do to validate my fields:

         $this->validate( $request, [
            'name'                 => __( 'required|max:255|unique:templates,name,NULL,id,company_id,:company_id', [
                'company_id' => $request->input( 'companies' )
            ] ),
            'modules'              => 'required|numeric',
            'companies'            => 'required|numeric',
            'start_date'           => 'required_with:limited_availability|date|before:end_date',
            'end_date'             => 'required_with:limited_availability|date|after:start_date',
            'indesign_location'    => __( 'required|file|mimetypes:application/zip|max::max_upload_size', [
                'max_upload_size' => config( 'file.max_size' )
            ] )
        ] );

What I want to achieve: The fields start_date and end_date should only be required (and therefore be validated) when the field limited_availability is present.

What happens now is that I don't get the message that the field is required, but I do get an error message on both date fields that the specified date is invalid.

How can I fix this problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire