CoachInfoRecord.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Models;
  3. use App\Enums\TechnicianAuthStatus;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Slowlyo\OwlAdmin\Models\BaseModel as Model;
  6. /**
  7. * 技师信息记录
  8. */
  9. class CoachInfoRecord extends Model
  10. {
  11. use SoftDeletes;
  12. protected $table = 'coach_info_records';
  13. protected $guarded = [];
  14. /**
  15. * 应该被转换为原生类型的属性
  16. *
  17. * @var array
  18. */
  19. protected $casts = [
  20. 'portrait_images' => 'array',
  21. ];
  22. /**
  23. * 应该被追加到模型数组的访问器
  24. *
  25. * @var array
  26. */
  27. protected $appends = ['state_text'];
  28. /**
  29. * 获取状态文本
  30. *
  31. * @return string
  32. */
  33. public function getStateTextAttribute(): string
  34. {
  35. return TechnicianAuthStatus::fromValue($this->state)?->label() ?? '未知状态';
  36. }
  37. /**
  38. * @Author FelixYin
  39. *
  40. * @description 信息记录所属技师
  41. */
  42. public function coach()
  43. {
  44. return $this->belongsTo('App\Models\CoachUser', 'coach_id');
  45. }
  46. }