Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel form html with PUT method for PUT routes

I Have this in my routes :

+--------+---------------------------+--------------+---------------------------                                                                                                                ---------+----------------+---------------+ | Domain | URI                       | Name         | Action                                                                                                                                             | Before Filters | After Filters | +--------+---------------------------+--------------+---------------------------                                                                                                                ---------+----------------+---------------+ |        | GET|HEAD /                |              | postcontroller                                                                                                                                     | auth           |               | |        | GET|HEAD login            |              | homecontroller@dologin                                                                                                                             |                |               | |        | POST login                |              | homecontroller@dologin                                                                                                                             |                |               | |        | GET|HEAD logout           |              | homecontroller@dologout                                                                                                                            |                |               | |        | GET|HEAD post             | post.index   | postcontroller@index                                                                                                                               |                |               | |        | GET|HEAD post/create      | post.create  | postcontroller@create                                                                                                                              |                |               | |        | POST post                 | post.store   | postcontroller@store                                                                                                                               |                |               | |        | GET|HEAD post/{post}      | post.show    | postcontroller@show                                                                                                                                |                |               | |        | GET|HEAD post/{post}/edit | post.edit    | postcontroller@edit                                                                                                                                |                |               | |        | PUT post/{post}           | post.update  | postcontroller@update                                                                                                                              |                |               | |        | PATCH post/{post}         |              | postcontroller@update                                                                                                                              |                |               | |        | DELETE post/{post}        | post.destroy | postcontroller@destroy  

Now, i want to make a form html that will use PUT method. Here it is my codes:

<form class="col-md-12" action="<?php echo URL::to('/');?>/post/<?=$post->postID?>" method="put">     <div class="form-group">         <textarea type="text" class="form-control input-lg" placeholder="Text Here" name="post"><?=$post->post?></textarea>     </div>     <div class="form-group">         <button class="btn btn-primary btn-lg btn-block" type="submit" value="Edit">Edit</button>     </div> </form>      

But i doesn't work to submit the form into post.edit.

I Have googled and i got solution that i must use

{{form:...etc 

But, i want the form still can done by CSS styling. Is there any solution guys? Thank You

like image 581
Richard Henokh Kurniawan Avatar asked Jan 26 '15 01:01

Richard Henokh Kurniawan


1 Answers

If you are using HTML Form element instead Laravel Form Builder, you must place method_field between your form opening tag and closing end. By doing this you may explicitly define form method type.

<form> {{ method_field('PUT') }} </form> 

For Laravel 5.1 and above

<form> @method('PUT') </form> 
like image 187
mistertandon Avatar answered Sep 28 '22 10:09

mistertandon