skip to Main Content

I am trying to validate multiple select field but is is not giving any error message, if i am not selecting any image. This is my code –

$validatedData = $this->validate([
    'images.*' => 'required|image'
]);

blade file code –

<input type="file" class="form-control" name="images" wire:model="images" multiple>
@error('images.*') <span class="text-danger">{{ $message }}</span> @enderror

2

Answers


  1. laravel validation errors in views presented in different way, i think this part of laravel docs is answer of your question

    https://laravel.com/docs/11.x/validation#quick-displaying-the-validation-errors

    Login or Signup to reply.
  2. Multiple select field works as an array and there is no need to add .* both in validation and blade file. so code will be –

    $validatedData = $this->validate([
        'images' => 'required|image'
    ]);
    
    <input type="file" class="form-control" name="images" wire:model="images" multiple>
    @error('images') <span class="text-danger">{{ $message }}</span> @enderror
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search