Home  >  Article  >  PHP Framework  >  Introduction to commonly used auxiliary functions in Laravel

Introduction to commonly used auxiliary functions in Laravel

藏色散人
藏色散人forward
2020-03-06 09:06:473883browse

Introduction to commonly used auxiliary functions in Laravel

There are many very useful helper functions in Laravel

1.csrf token form

{{ csrf_token() }}

This way you can directly obtain Laravel itself The maintained csrf_token is usually used like this:

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

Or you can also directly get the hidden form of the csrf token:

{!! csrf_field() !!}

This will directly output content similar to the following in html. :

<input name="_token" value="3E0fFDOHQylQFdM1UQ8pjJyMuN8YP5erC6VxoHY8" type="hidden" />

2. Generate method form

When using resource routing, there are some methods that the browser cannot support natively, such as DELETE, PATCH PUT, etc. At this time, you can use the following code to generate method forms and simulate these requests:

 {{ method_field(&#39;DELETE&#39;) }}

Generated HTML:

<input type="hidden" name="_method" value="DELETE">

For more technical articles related to the laravel framework, please visit laravel tutorialColumn!

The above is the detailed content of Introduction to commonly used auxiliary functions in Laravel. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete