123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Models;
- use App\Traits\ModelHelpers;
- use Illuminate\Database\Eloquent\Model;
- class Student extends Model
- {
- use ModelHelpers;
- protected $appends = ['auth_status_text', 'type_text'];
- protected $casts = [
- 'type' => 'integer',
- 'auth_status' => 'integer',
- ];
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_OK => '正常',
- self::STATUS_PAUSE => '暂停'
- ];
- const TYPE_STUDENT = 0;
- const TYPE_TEACHER = 1;
- public static $typeMaps = [
- self::TYPE_STUDENT => '学生',
- self::TYPE_TEACHER => '老师'
- ];
- const AUTH_STATUS_WAIT = 0;
- const AUTH_STATUS_OK = 1;
- const AUTH_STATUS_NO = 2;
- public static $authStatusMaps = [
- self::AUTH_STATUS_WAIT => '待认证',
- self::AUTH_STATUS_OK => '认证成功',
- self::AUTH_STATUS_NO => '认证失败',
- ];
- protected $guarded = [];
- public function user()
- {
- return $this->belongsTo(User::class);
- }
- public function getAuthStatusTextAttribute()
- {
- return self::$authStatusMaps[$this->attributes['auth_status']];
- }
- public function getTypeTextAttribute()
- {
- return self::$typeMaps[$this->attributes['type']];
- }
- public function resource()
- {
- return $this->hasOne(Upload::class, 'id', 'imgs');
- }
- }
|