海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. class Agent extends BaseModel
  6. {
  7. use HasFactory, SoftDeletes;
  8. public function getLogoAttribute($value): string
  9. {
  10. return $value ? $this->host . $value : '';
  11. }
  12. public function getLicensePicAttribute($value): string
  13. {
  14. return $value ? $this->host . $value : '';
  15. }
  16. public function setLogoAttribute($value)
  17. {
  18. //修改器里面$this->host变量为空
  19. $this->attributes['logo'] = str_replace(env('APP_URL'), '', $value);
  20. }
  21. public function setLicensePicAttribute($value)
  22. {
  23. //修改器里面$this->host变量为空
  24. $this->attributes['license_pic'] = str_replace(env('APP_URL'), '', $value);
  25. }
  26. public function setPasswordAttribute($value)
  27. {
  28. //新增时
  29. if ($value && empty($this->attributes['password'])) {
  30. $this->attributes['password'] = $this->passMd5($value);
  31. }
  32. //编辑时
  33. else if ($value && !empty($this->attributes['password']) && $this->attributes['password'] != $value) {
  34. $this->attributes['password'] = $this->passMd5($value);
  35. }
  36. }
  37. public function agentInfo()
  38. {
  39. return $this->hasOne(AgentInfo::class);
  40. }
  41. }