'require|checkProduct', 'name' => 'require|length:1,50', 'points' => 'require|integer|gt:0', 'amount' => 'require|float|gt:0', ]; protected $message = [ 'id.require' => '商品id不能为空', 'name.require' => '商品名称不能为空', 'name.length' => '商品名称长度须在1-50位字符', 'points.require' => '积分数不能为空', 'points.integer' => '积分数须为整数', 'points.gt' => '积分数须大于0', 'amount.require' => '金额不能为空', 'amount.gt' => '金额须大于0', ]; public function sceneAdd() { return $this->remove('id', 'require|checkProduct'); } public function sceneEdit() { } public function sceneDetail() { return $this->only(['id']); } public function sceneDelete() { return $this->only(['id']); } public function checkProduct($value) { $product = PointsProduct::findOrEmpty($value); if ($product->isEmpty()) { return '积分商品不存在'; } return true; } }