by Devin Yang
(This article was automatically translated.)

Published - 6 years ago ( Updated - 6 years ago )

Why does Laravel need Form Method Spoofing?
Because HTML forms do not support PUT, PATCH and DELETE and other actions, so On Laravel
When submitting the HTML form, we need to send it as an HTTP request through a hidden _method input field.
In this way, Laravel's Restful style routing can know whether the request is PUT or PATCH...etc.

Prior to Laravel 5.5, forms could embed two hidden input fields:
<form action="/foo/bar" method="POST">
    <input type="hidden" name="_method" value="PUT">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
or
<form action="/foo/bar" method="POST">
    {{ method_field('PUT') }}
    {{ csrf_field() }}
</form>
After Laravel 5.6, we can also achieve the same effect through Blade directive:
<form action="/foo/bar" method="POST">
    @method('PUT')
    @csrf
</form>

 

Tags: laravel

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


laravel,oauth2

My most used Laravel passport directives

Laravel provides quite a lot of useful packages, such as Passport is one of them, when the website needs to set up its own OAuth2 authentication host, it really saves time and effort. Take this site as an example, because the front-end and back-end separation mechanisms are adopted (there are two different Laravel projects), and I verify them through the front-end WEB. Basically, I have many other different projects, and they all rely on OAuth2 provided by Laravel to handle cross-domain authentication.

laravel,trait,php

My Browser Trait, webp image file support function detection and whether it is a mobile phone detection

I believe that many people are familiar with PHP trait, because Laravel can be seen everywhere, but I still write it and share it with those who are destined. PHP trait allows two different CLASS to use the same method. It not only reduces the complexity, but also allows the code to be reused. So it should be very convenient to put a Browser series function on Laravel's ViewServiceProvider 😝

d-laravel,docker

D-Laravel v1.2.1 version change description (recommended update, must avoid stepping on thunder)

D-Laravel v1.2.1 revision instructions use GuzzleHttp\Client; When posting, there is an access denied problem. If you are upgrading from an older version, you may need to adjust the configuration file in etc/default-ssl.conf (if there is one) Please adjust php:9000 to web:9000, you can adjust it by executing ./console secure once. In the docker-compose configuration file, change the PHP-FPM container to network_mode: "service:web"...