Laravel form html with PUT method for PUT routes

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Laravel Form HTML with PUT Method for PUT Routes Body:

In a Laravel application, it is vital to understand the use of different HTTP methods. These methods are used to indicate the type of request being sent by the client and how the server should process it. The form method attribute determines which HTTP method the submitted data will be sent with, either GET or POST for standard requests or PUT in this case. Let's elaborate further on how to handle PUT requests using forms.

Firstly, ensure your routes are properly configured to accept and process PUT requests. You can have separate named routes for different actions like creating, storing, updating, deleting, etc.:

+--------+---------------------------+--------------+---------------------------                                                                                                                ---------+----------------+---------------+
| 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 

Next, let's create a form with the PUT method. In your HTML code, you can use the following structure:

<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>     

However, as you mentioned, if your primary goal is to keep the form styled using CSS, it's recommended to use Laravel Form Builder. This will ensure that the form submission method will automatically be set to PUT while maintaining your desired styling.

In short, make sure your routes are configured correctly for PUT methods and choose the appropriate HTML structure or utilize Laravel's Form builder to handle the submission of forms with the PUT method. Remember that forms are meant to be submitted using HTTP requests, and the specific method used will dictate how the data is processed by the server.

Conclusion: Ensuring proper route configuration, choosing between HTML code or Form Builder, and ensuring your form's method attribute matches your desired request type is fundamental for handling PUT requests in Laravel applications. This guarantees a smooth user experience while maintaining data security and effectiveness.