表单请求验证
-
新建一个controller
php artisan make:controller TestControl
2.表单数据验证函数create
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class TestController extends Controller
{
public function create(Request $request){
$rq=\Request::all();
$val=\Validator::make($rq,['username'=>'required|between:4,10|unique:users','password'=>'required|between:6,200']);
if($val->fails()){
return $val->errors();
}
else{
return "验证成功";
}
}
}