1
votes

Form is file uploader. Laravel doesnt give me error if validation fails on mime type. If it fails on input required it gives me error on my upload page properly. It looks like validation is right but it only doesnt give me back error if mime type is wrong, because it doesnt upload file if file is wrong.

route

Route::post('/newfile', function (Request $request) {

$validator = Validator::make($request->all(), [
    'userFile' => 'required|mimes:zip',
]);

if ($validator->fails()) {
    return redirect('/upload')
        ->withErrors($validator);
} else {

view

   @include('errors.errors')

<form action="{{ url('newfile') }}" method="POST" id="uploadForm" class="form-horizontal" enctype="multipart/form-data">
    {!! csrf_field() !!}

    <div class="input-group">
                <span class="input-group-btn">
                    <span class="btn btn-primary btn-file">
                        Browse&hellip; <input name="userFile" id="userFile" type="file" />
                    </span>
                </span>
        <input type="text" class="form-control" readonly>
    </div>

    <div>
        <button type="submit" id="btnSubmit" value="Submit" class="btn btn-success">Upload</button>

        <div class="progress">

        </div>
    </div>
</form>

error

    @if (count($errors) > 0)
        <!-- Form Error List -->
<div class="alert alert-danger">
    <strong>Whoops! Something went wrong!</strong>

    <br><br>

    <ul>
        @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
    </ul>
</div>
@endif
1

1 Answers

0
votes

Fixed, my javascript code for upload blocked errors from validator.