1
votes

I'm having a bit of an issue when it comes to updating a form and and having an file input. Here is what I am working with.

I have a form in laravel 5.1 which has a post method and a hidden 'Patch' method. This works as is should updating the fields that are in the form. However, when it introduce:

<input type="file" id="profile_picture" name="image_url" />

into the form, i get a:

MethodNotAllowedHttpException in RouteCollection.php line 218:

laravel error. I have tried changing the

 <input type='hidden' name='_method' value='PATCH'>

to PUT and it still doesnt like it.

My form looks like this:

<form action='{{url("profiles/$user->id")}}' method="post" class="form-horizontal" enctype="multipart/form-data">

route resource looks like this:

Route::resource('profiles', 'ProfilesController');

I can't figure out what I am missing here...Any help is much appreciated.

2
Are you using the same form for both post and patch requests? - Orkhan Farmanli
this form is used only for an update - max234435

2 Answers

0
votes

I believe it has to do with the exact route you are typing out in the "action" parameter matching up with the profile controller's update method.

Try changing

action'{{url("profiles/$user->id")}}'

to

action='{{ route("profiles.update", $user->id) }}'

Additionally, you could use the Laravel Collective HTML package to simply opening and closing of forms.

0
votes

Also for POST Request types, you need to send the CSRF token along with your form data. If you are using laravel blade template in your view, you may use

{{ csrf_field() }}

which translates to

<input type="hidden" name="_token" value={{ csrf_token() }}

Please refer the documentation for this.