Laravel 的数据验证 somethingElseIsInvalid () 方法不存在

在做数据验证时候发现 Method App\Http\Requests\SignupPost::somethingElseIsInvalid does not exist. 报错
然后 我在整个框架内搜索 somethingElseIsInvalid 这个方法 发现没有
以下是我的数据验证类

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use App\Models\Signup;
use Illuminate\Support\Facades\Validator;
class SignupPost extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'pname' => 'required|max:30',
            'name'  => 'required|max:20',
            'mobile'=> 'required|length:11',
            'sex'=>'required',
            'birthday'=>'required',
            'school'=>'required',
            'province'=>'required',
            'score'=>'required|numeric',
            'class'=>'required',
            'idcard_start'=>'required|date',
            'idcard_end'=>'required|date',
            'wechart'=>'required',
            'parent'=>'required',
            'passport_start'=>'required|date',
            'passport_end'=>'required|date',
            'img_1'=>'required',
            'img_2'=>'required',
            'img_3'=>'required',
            'img_4'=>'required',
            'img_5'=>'required',
            'img_6'=>'required',
            'img_7'=>'required',
            'img_8'=>'required',
            'img_9'=>'required',
            'img_10'=>'required'
        ];
    }
    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array
     */
    public function messages()
    {

        return [
            'max' => ':attribute 不超过.',
            'length' => ':attribute 请输入正确的手机号.',
            'required' => ':attribute 不能为空.',
            'date' => ':attribute 时间格式有误',
            'numeric'=>':attribute 必须为数字',
        ];

    }

    /**
     *  配置验证器实例。
     *
     * @param  \Illuminate\Validation\Validator  $validator
     * @return void
     */
    public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            if ($this->somethingElseIsInvalid()) {
                $validator->errors()->add('field', 'Something is wrong with this field!');
            }
        });
    }
}

laravel的数据验证somethingElseIsInvalid()方法不存在
这个是我的 使用postman 请求数据的结果。发现这个方法不存在。我的版本是laravel-admin5.7 的版本
请问这个应该如何解决

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

somethingElseIsInvalid 我看了下文档,,,我猜,,,这个方法,,,只是文档中的一种当作说明的伪方法,,,只是告诉你,,,在还有其他无效字段(somethingElseIsInvalid)的情况下,就向错误包中添加其他错误信息,,,而不是真正的有这个方法,,,

4年前 评论
讨论数量: 1

somethingElseIsInvalid 我看了下文档,,,我猜,,,这个方法,,,只是文档中的一种当作说明的伪方法,,,只是告诉你,,,在还有其他无效字段(somethingElseIsInvalid)的情况下,就向错误包中添加其他错误信息,,,而不是真正的有这个方法,,,

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!