{:token\_field()} 模板中输出令牌
{:token\_meta()} ajax提交
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta\[name="csrf-token"\]').attr('content')
}
});
Route::post('blog/save','blog/save')\->token(); 路由中使用验证
think\\facade\\Validate
$rule \= \[
'name' \=> 'require|max:25',
'age' \=> 'number|between:1,120',
'email' \=> 'email',
\];
$msg \= \[
'name.require' \=> '名称必须',
'name.max' \=> '名称最多不能超过25个字符',
'age.number' \=> '年龄必须是数字',
'age.between' \=> '年龄只能在1-120之间',
'email' \=> '邮箱格式错误',
\];
$data \= \[
'name' \=> 'thinkphp',
'age' \=> 10,
'email' \=> 'thinkphp@qq.com',
\];
$validate \= Validate::rule($rule)\->message($msg);
$result \= $validate\->check($data);
if(!$result) {
dump($validate\->getError());
}