一.创建控制器引入验证
Cs 是验证内容
<?php
namespace App\Http\Controllers\Cs;
use App\Http\Controllers\Controller;
use App\Http\Requests\Cs;
class IndexController extends Controller
{
public function index(Cs $request){
return $request;
}
}
二.创建验证内容
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class Cs extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;// 授权 必须是true false会报没有访问权限的错误
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required',
'body' => 'required',
];
}
public function messages(){
return [
'title.required' => '标题不能为空',
'body.required' => '内容不能为空',
];
}
}
验证函数(本文章总结于)
https://xueyuanjun.com/post/21478
完了~
网友评论