types = collect([ collect(['key' => 1, 'value' => 1, 'show_value' => '公告']), collect(['key' => 2, 'value' => 2, 'show_value' => '活动']), collect(['key' => 3, 'value' => 3, 'show_value' => '视频']), collect(['key' => 4, 'value' => 4, 'show_value' => '文章']), ]); } public function getModelType($type) { return in_array($type, [1, 2, 3, 4]) ? $type : 1; } public function getModelName($type) { $item = $this->types->where('key', $type)->first(); return empty($item) ? '公告' : $item['show_value']; } }