需要在 xxx.blade.php
文件中使用,form
表单(同步)提交数据是有带标签的,ajax
(异步)使用字符串的。
<form action="" method="post">
{{-- 方式一:laravel 5.6 及以后版本,也是 csrf_field() 的简写 --}}
@csrf
{{-- 方式二:laravel 5.6 以下老版本 --}}
{{ csrf_field() }}
{{-- 输出上面的 token 字符串 --}}
{{ csrf_token() }}
<div>账号:<input type="text" name="account"></div>
<div>密码:<input type="password" name="pwd"></div>
<div>邮件:<input type="email"></div>
<input style="margin-top: 5px;" type="submit" value="添加用户">
</form>