| 123456789101112131415161718192021222324252627282930313233343536 | 
							- <?php
 
- namespace App\Models;
 
- use Illuminate\Database\Eloquent\Model;
 
- class Content extends Model
 
- {
 
-     protected $table = 'contents';
 
-     protected $guarded = [];
 
-     protected $types;
 
-     public function __construct(array $attributes = [])
 
-     {
 
-         parent::__construct($attributes);
 
-         $this->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'];
 
-     }
 
- }
 
 
  |