📜  laravel 请求创建和更新的验证规则 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:48.490000             🧑  作者: Mango

代码示例1
public function rules()
    {
        $rules = [
            'name' => 'required|string|unique:products|max:255',
        ];

        if (in_array($this->method(), ['PUT', 'PATCH'])) {
            $product = $this->route()->parameter('product');

            $rules['name'] = [
                'required',
                'string',
                'max:255',
                Rule::unique('loan_products')->ignore($product),
            ];
        }

        return $rules;
    }