ManagerModel.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * 描述.
  4. *
  5. * @author nj
  6. * @date 2021-05-18 20:46:19
  7. */
  8. namespace App\Models\Mysql;
  9. class ManagerModel extends BaseMysql
  10. {
  11. protected $table = 'manager';
  12. /**
  13. * UUID 键名
  14. * @var string
  15. */
  16. protected $uuidKeyName = 'manager_uid';
  17. /**
  18. * 隐藏字段.
  19. *
  20. * @var array
  21. */
  22. protected $hidden = ['password', 'salt', 'otp_secret'];
  23. /**
  24. * The "booted" method of the model.
  25. *
  26. * @return void
  27. */
  28. protected static function boot()
  29. {
  30. parent::boot();
  31. self::creating(function ($model) {
  32. $model->{$model->uuidKeyName} = self::generateId($model->uuidKeyName);
  33. });
  34. self::created(function ($model) {
  35. $uuid = hashEncodeId($model->id);
  36. $model->{$model->uuidKeyName} = $uuid;
  37. $model->save();
  38. });
  39. }
  40. /**
  41. * 关联角色.
  42. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  43. */
  44. public function role()
  45. {
  46. return $this->hasOne(PermissionRoleModel::class, 'id', 'role_id');
  47. }
  48. }