but it's not working
What's the current behavior?
I guess you're missing some validations.
$request->validate([
// ...
`upload` => ['required', 'array']
'upload.*' => ['image', 'mimes:jpg,jpeg,png']
]);
Hello, I'm trying to validate multiple file types with Laravel validation, but it's not working and I cannot figure out why, this is my code:
Blade form:
<form method="POST" action="{{ route('nova_Pessoa') }}" enctype="multipart/form-data">
<div class="upload-img-component">
<div class="form-row">
<div class="form-group col">
<label class="text-nowrap">Fotos</label>
<div class="input-group CM @error('upload') is-invalid @enderror" id="foto">
<label for="upload" class="label-foto pl-2 ml-1 pt-2 mt-1 text-muted"></label>
<input type="file" class="form-control input-foto" accept="image/png, image/jpg, image/jpeg" id="upload" name="upload[]" multiple>
<div class="input-group-append">
<label for="upload" class="btn btn-upl-CM m-1">
<i class='bx bxs-cloud-upload btn-upl-icon-CM'></i>
Escolha uma ou mais fotos
</label>
</div>
</div>
@error('upload')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="form-row">
<div class="form-group col">
<div class="rounded img-preview p-3"></div>
</div>
</div>
</div>
<button type="reset" data-dismiss="modal" class="btn CM large cancel-CM ml-1 mr-1 shadow-none">Cancelar</button>
<button type="submit" class="btn CM large save-CM ml-1 shadow-none"> Salvar </button>
</form>
Controller:
public function nova_Pessoa(Request $request){
$request->validate([
'nome' => ['required', 'string', 'max:60'],
'telefone' => ['max:15'],
'CPF_RG' => ['max:11'],
'alcunha' => ['max:60'],
'observacao_pessoa' => ['max:65535'],
'upload.*' => ['mimes:jpg,jpeg,png']
]);
}
Ok, I have found the problem, the validation it's indeed working, what was wrong was how they were shown in the blade, to show the errors with a array variable I need to put with this syntax:
<div class="input-group CM @error('upload.*') is-invalid @enderror" id="foto">
@error('upload.*')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
Working with laravel 10
Please or to participate in this conversation.