How to validate the order that the images are selected

1

It is difficult to find a title that details. step to explain.

I have a form where I enter up to 5 images. But only the first one requires it if or if (as the main image of the article). The other 4 are optional. These images are entered with inputs

What I need to do is that by php or by validation of the request, I would prefer the latter, do not allow me to enter an image of any input, but keep the order, first the input of the main image, then the second that is already optional and so until the last one if you want to

@section('contenido')
{!!     Form::open(['route'=>'articulos.store','method'=>'POST','files'=>true]) !!}

    <br>
    <div class="form-group">
        {!! Form::label('imagen_1','Imagen Principal:') !!}
        {!! Form::file('imagen_1') !!}
        <br>
        {!! Form::text('descripcion_1',null,['class'=>'form-control','placeholder'=>'Descripcion de la foto...']) !!}

    </div>
    <div class="form-group">
        {!! Form::label('imagen_2','Imagen 2:') !!}
        {!! Form::file('imagen_2') !!}
        <br>
        {!! Form::text('descripcion_2',null,['class'=>'form-control','placeholder'=>'Descripcion de la foto...']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('imagen_3','Imagen 3:') !!}
        {!! Form::file('imagen_3') !!}
        <br>
        {!! Form::text('descripcion_3',null,['class'=>'form-control','placeholder'=>'Descripcion de la foto...']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('imagen_4','Imagen 4:') !!}
        {!! Form::file('imagen_4') !!}
        <br>
        {!! Form::text('descripcion_4',null,['class'=>'form-control','placeholder'=>'Descripcion de la foto...']) !!}
    </div>
    <div class="form-group">
        {!! Form::label('imagen_5','Imagen 5:') !!}
        {!! Form::file('imagen_5') !!}
        <br>
        {!! Form::text('descripcion_5',null,['class'=>'form-control','placeholder'=>'Descripcion de la foto...']) !!}
    </div>
    <div class="form-group">
        {!! Form::submit('Agregar articulo',['class'=>'btn btn-primary']) !!}
    </div>
    {!! Form::close() !!}

@endsection
    
asked by Cidius 07.11.2016 в 13:25
source

1 answer

0

The Laravel way of doing this is to use the validations for those fields, a combination of several validations of required* .

I can not prove it at this time, but I would use the validation required for the first field and required_with or required_if for the following images:

public function rules()
{
    return [
        'imagen_1' => 'required',
        'imagen_2' => 'required_with:imagen_3',
        'imagen_3' => 'required_with:imagen_4',
        'imagen_4' => 'required_with:imagen_5',
    ];
}
    
answered by 07.11.2016 / 15:58
source