blendpajaziti's avatar

File validation error

I have a form with a pdf upload field which has pdf only validation. If I try to upload another file type I don't get a validation error but a MethodNotAllowedHttpException. Why is that happening?

0 likes
10 replies
rawilk's avatar

Please show your validation code, and how you're uploading the file, otherwise people can't really help you.

1 like
blendpajaziti's avatar

My validation:

class ApplyValidation extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'cv' => 'mimes:pdf',
        ];
    }
}

My form:

<form action="{{ route('apply.store') }}" method="post" enctype="multipart/form-data">

           {{ csrf_field() }}

            <div class="form-group">
                    <label for="cv">CV <small> PDF ONLY</small> </label>
                    <input type="file" class="form-control-file" name="cv" id="cv">
            </div>

<button type="submit" class="btn btn-primary">SUBMIT</button>

</form>
blendpajaziti's avatar

Route:

Route::post('/apply_store',[
        'uses' => 'ApplyController@store',
        'as' => 'apply.store'
    ]);

Controller:

 public function store(ApplyValidation $request){

        $apply = new Apply;

        if($request->hasFile('cv')){
            \Cloudder::upload($request->file('cv'));
            $cv = \Cloudder::getResult();
            if($cv){
                $apply->cv = $cv['url'];
            }
        }

        $apply->save();

        return view('home');

    }

I am using cloudinary for file uploading

rawilk's avatar

I forgot about the routes file, that would also be helpful to see. I'm guessing you made the route a GET route, and you're trying to POST, which is probably why you're getting the MethodNotAllowedHttpException.

1 like
rawilk's avatar

Nevermind what I just said, you posted just right before I did.

1 like
blendpajaziti's avatar

No my route is actually set to POST, but i think it may have something to do with the cloud service i'm using. When I hit back from the error page I see the error that was supposed to appear.

crnkovic's avatar

dd($request->all()); just before the $apply = new Apply; line and dump here the output.

blendpajaziti's avatar

It doesn't dump the data, the exeption appears only. But when I upload a correct pdf file it dumps the data correctly including the file. I'm just guessing the error may be caused by cloudinary.

blendpajaziti's avatar

I also use Cloudder package which allows me to use cloudinary in Laravel

Please or to participate in this conversation.