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

Introduction to commonly used auxiliary functions in Laravel

藏色散人
Release: 2020-03-06 09:06:47
forward
3911 people have browsed it

Introduction to commonly used auxiliary functions in Laravel

There are many very useful helper functions in Laravel

1.csrf token form

{{ csrf_token() }}
Copy after login

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" />
Copy after login

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

{!! csrf_field() !!}
Copy after login

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

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

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;) }}
Copy after login

Generated HTML:

<input type="hidden" name="_method" value="DELETE">
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template