It is difficult to find a title that details. I will explain.
I have a form where I enter up to 5 images. But only the first requires yes or yes (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 validations of the request, I would prefer the latter, it does not allow me to enter an image from any input, but rather preserve the order, first the input of the main image, then the second that is already optional and so on until the last if you want
@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
The Laravel way of doing it is to use the validations for those fields, a combination of various validations from
required*
.I can't test it right now, but I would use validation
required
for the first field andrequired_with
orrequired_if
for the following images: