Fetch error message generated by file upload validator

Posted 9 months ago by cosminc

Hello everybody,

I'm building a form with multiple fields and among those I also have a file upload input.

I'm trying to display an error message after each input, but it seems that this logic doesn't work for the file upload one.

<div class="form-group">
    <label for="attachment">Attachment</label>
    <input id="attachment" type="file" class="form-control" name="attachment">

@if ($errors->has('attachment'))
    <span class="error">
        <strong>{{ $errors->first('attachment') }}</strong>

It seems that I can only get the error from the input field with a code like this:

@if ($errors->any())
    @foreach ($errors->all() as $error)
        <div class="alert alert-danger" role="alert">
            {{ $error }}

So my question is: what do I need to do in order to fetch the error for that specific field?

Thank you.

Please sign in or create an account to participate in this conversation.