Student.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Student extends Model
  6. {
  7. use ModelHelpers;
  8. protected $appends = ['auth_status_text', 'type_text'];
  9. protected $casts = [
  10. 'type' => 'integer',
  11. 'auth_status' => 'integer',
  12. ];
  13. const STATUS_OK = 1;
  14. const STATUS_PAUSE = 0;
  15. public static $statusMaps = [
  16. self::STATUS_OK => '正常',
  17. self::STATUS_PAUSE => '暂停'
  18. ];
  19. const TYPE_STUDENT = 0;
  20. const TYPE_TEACHER = 1;
  21. public static $typeMaps = [
  22. self::TYPE_STUDENT => '学生',
  23. self::TYPE_TEACHER => '老师'
  24. ];
  25. const AUTH_STATUS_WAIT = 0;
  26. const AUTH_STATUS_OK = 1;
  27. const AUTH_STATUS_NO = 2;
  28. public static $authStatusMaps = [
  29. self::AUTH_STATUS_WAIT => '待认证',
  30. self::AUTH_STATUS_OK => '认证成功',
  31. self::AUTH_STATUS_NO => '认证失败',
  32. ];
  33. protected $guarded = [];
  34. public function user()
  35. {
  36. return $this->belongsTo(User::class);
  37. }
  38. public function getAuthStatusTextAttribute()
  39. {
  40. return self::$authStatusMaps[$this->attributes['auth_status']];
  41. }
  42. public function getTypeTextAttribute()
  43. {
  44. return self::$typeMaps[$this->attributes['type']];
  45. }
  46. public function resource()
  47. {
  48. return $this->hasOne(Upload::class, 'id', 'imgs');
  49. }
  50. }