我使用验证规则创建了Request类:
class RegistrationRequest extends Request{
public function authorize()
{
return true;
}
public function rules()
{
return [
'number' => 'required|regex:/(01)[0-9]{9}/',
'test' => 'required'
];
}
}
但是验证永远不会在控制器中起作用。
public function register(RegistrationRequest $request)
return false;
}
答案 0 :(得分:2)
您应在请求类中加入FormRequest
use Illuminate\Foundation\Http\FormRequest;
class RegistrationRequest extends FormRequest{
public function authorize()
{
return true;
}
public function rules()
{
return [
'number' => 'required|regex:/(01)[0-9]{9}/',
'test' => 'required'
];
}
}
文档:https://laravel.com/docs/5.7/validation#form-request-validation