PHP code example of slpcode / form-request-validation
1. Go to this page and download the library: Download slpcode/form-request-validation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
slpcode / form-request-validation example snippets
use Slpcode\FormRequestValidation\FormRequest;
class TestRequest extends FormRequest
{
/**
* 设置验证规则
*
* @return array
*/
protected function rules()
{
return [
'name' => '
* @return array
*/
protected function attributes()
{
return [];
}
}
// 进行验证,如果验证不通过则会抛出 Slpcode\FormRequestValidation\Exceptions\ValidationException 异常
// 通过后返回request实例
$request = (new TestRequest)->check();
class BaseRequest extends \Slpcode\FormRequestValidation\FormRequest
{
public function extend(){
$this->getValidator()->extend('mobile', function ($attribute, $value, $parameters, $validator) {
// return ...;
}, ':attribute 格式不正确');
}
}