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


dlaravel

[D-Laravel] about chowner.

About D-Laravel's Chowner This article explains the function of chowner in D-Laravel. If you are a Linux user, you may need to do this.

laravel,ModelFactory

How do I use ModelFactory to create Chinese fake data in Laravel

In Laravel, how to use ModelFactory to create Chinese fake data? In this content, I introduce the way I tried it out, Come in quickly for reference..

laravel,sftp

Use Laravel's Storage SFTP Drvier for remote file upload

Why do I separate the front and back of the website? My idea is very simple, that is to rely on a set of background to control all the website data in the foreground. Assuming that the front-end website is a pure marketing website, it is nothing more than the subject content, just like the article above, without any particularly complicated logic. Therefore, it is enough to set up the backend database and connect different frontends. Then there is the last question, how can my backend HTML editor post pictures directly to the frontend? Laravel's Storage SFT Driver is a good antidote.