'require|integer|gt:0|checkLive', 'match_id' => 'require|integer|gt:0|checkMatch', 'title' => 'require|checkTrimmedTitle', 'source_url' => 'require|checkTrimmedSourceUrl', ]; protected $message = [ 'id.require' => '直播线路id不能为空', 'id.integer' => '直播线路id须为整数', 'id.gt' => '直播线路id须大于0', 'match_id.require' => '赛事id不能为空', 'match_id.integer' => '赛事id须为整数', 'match_id.gt' => '赛事id须大于0', 'title.require' => '直播标题不能为空', 'title.length' => '直播标题长度须在1-255位字符', 'source_url.require' => '源地址不能为空', 'source_url.max' => '源地址长度不能超过500位字符', ]; public function sceneDetail() { return $this->only(['id']); } public function sceneAdd() { return $this->remove('id', 'require|integer|gt:0|checkLive') ->only(['match_id', 'title', 'source_url']); } public function sceneEdit() { return $this->only(['id', 'match_id', 'title', 'source_url']); } public function sceneDelete() { return $this->only(['id']); } public function checkLive($value) { $live = MatchLive::findOrEmpty($value); if ($live->isEmpty()) { return '直播线路不存在'; } return true; } public function checkMatch($value) { $match = MatchEvent::findOrEmpty($value); if ($match->isEmpty()) { return '赛事不存在'; } return true; } public function checkTrimmedTitle($value) { if (!is_scalar($value)) { return '直播标题格式错误'; } $value = trim((string) $value); if ($value === '') { return '直播标题不能为空'; } if (mb_strlen($value) > 255) { return '直播标题长度须在1-255位字符'; } return true; } public function checkTrimmedSourceUrl($value) { if (!is_scalar($value)) { return '源地址格式错误'; } $value = trim((string) $value); if ($value === '') { return '源地址不能为空'; } if (mb_strlen($value) > 500) { return '源地址长度不能超过500位字符'; } return true; } }