Laravel-表单验证

2020-01-15  本文已影响0人  CicadaRika

独立验证类

权限验证方法

    public function authorize()
    {
        return true;
    }

验证规则

    public function rules()
    {
        return [
            'name' => ['required', 'min:50'],
        ];
    }

抛出错误

  public function failedValidation($validator)
    {
        $error = $validator->errors()->all();
        throw new HttpResponseException(response()->json(['code' => 1, 'message' => $error[0]]));
    }
上一篇下一篇

猜你喜欢

热点阅读