CoachInfoRecord.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. 'life_photos' => 'array'
  22. ];
  23. /**
  24. * 应该被追加到模型数组的访问器
  25. *
  26. * @var array
  27. */
  28. protected $appends = ['state_text'];
  29. /**
  30. * 获取状态文本
  31. */
  32. public function getStateTextAttribute(): string
  33. {
  34. $value = $this->state;
  35. if ($value !== null) {
  36. $status = TechnicianAuthStatus::fromValue($value);
  37. } else {
  38. // 处理 null 值的情况,例如设置默认状态或抛出异常
  39. }
  40. return $status?->label() ?? '未知状态';
  41. }
  42. /**
  43. * @Author FelixYin
  44. * @description 信息记录所属技师
  45. */
  46. public function coach()
  47. {
  48. return $this->belongsTo(CoachUser::class, 'coach_id', 'id');
  49. }
  50. // public function getStateAttribute($value)
  51. // {
  52. // return $value !== null ? TechnicianAuthStatus::fromValue($value) : null;
  53. // }
  54. }