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
50 lines
1.2 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Agent extends BaseModel
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
public function getLogoAttribute($value): string
|
|
{
|
|
return $value ? $this->host . $value : '';
|
|
}
|
|
|
|
public function getLicensePicAttribute($value): string
|
|
{
|
|
return $value ? $this->host . $value : '';
|
|
}
|
|
|
|
public function setLogoAttribute($value)
|
|
{
|
|
//修改器里面$this->host变量为空
|
|
$this->attributes['logo'] = str_replace(env('APP_URL'), '', $value);
|
|
}
|
|
|
|
public function setLicensePicAttribute($value)
|
|
{
|
|
//修改器里面$this->host变量为空
|
|
$this->attributes['license_pic'] = str_replace(env('APP_URL'), '', $value);
|
|
}
|
|
|
|
public function setPasswordAttribute($value)
|
|
{
|
|
//新增时
|
|
if ($value && empty($this->attributes['password'])) {
|
|
$this->attributes['password'] = $this->passMd5($value);
|
|
}
|
|
//编辑时
|
|
else if ($value && !empty($this->attributes['password']) && $this->attributes['password'] != $value) {
|
|
$this->attributes['password'] = $this->passMd5($value);
|
|
}
|
|
}
|
|
|
|
public function agentInfo()
|
|
{
|
|
return $this->hasOne(AgentInfo::class);
|
|
}
|
|
}
|