SpecialistCloumn.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Models;
  3. use Encore\Admin\Traits\ModelTree;
  4. use Encore\Admin\Traits\AdminBuilder;
  5. class SpecialistCloumn extends SoftBaseModel
  6. {
  7. use ModelTree, AdminBuilder;
  8. public function __construct(array $attributes = [])
  9. {
  10. parent::__construct($attributes);
  11. $this->setParentColumn('pid');
  12. $this->setOrderColumn('rank');
  13. $this->setTitleColumn('name');
  14. }
  15. /**
  16. * 所有一级
  17. * @var integer
  18. */
  19. const PID_0 = 0;
  20. /**
  21. * 是否显示 0:不显示
  22. * @var integer
  23. */
  24. const IS_SHOW_0 = 0;
  25. /**
  26. * 是否显示 1:显示
  27. * @var integer
  28. */
  29. const IS_SHOW_1 = 1;
  30. static public $isShowMap = [
  31. self::IS_SHOW_0 => '不显示',
  32. self::IS_SHOW_1 => '显示'
  33. ];
  34. protected $casts = ['banner'=>'json'];
  35. public function tags(){
  36. return $this->hasMany(SpecialistCloumnTag::class, 'specialist_cloumn_id', 'id');
  37. }
  38. public function getPicAttribute()
  39. {
  40. return isset($this->attributes['pic']) ? config('console.pic_path').$this->attributes['pic'] : NULL;
  41. }
  42. public function getBannerAttribute($value)
  43. {
  44. return array_values(json_decode($value, true) ?: []);
  45. }
  46. public function setBannerAttribute($value)
  47. {
  48. $this->attributes['banner'] = json_encode(array_values($value));
  49. }
  50. }