Browse Source

增加修改器,图片保存时去掉域名

dev
李可松 4 years ago
parent
commit
0068cf1d2e
  1. 7
      app/Models/Advertising.php
  2. 12
      app/Models/Agent.php
  3. 8
      app/Models/Article.php
  4. 14
      app/Models/Channel.php
  5. 10
      app/Models/Order.php

7
app/Models/Advertising.php

@ -7,8 +7,15 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
class Advertising extends BaseModel
{
use HasFactory;
public function getPictureAttribute($value)
{
return $value ? $this->host . $value : '';
}
public function setPictureAttribute($value)
{
//修改器里面$this->host变量为空
$this->attributes['picture'] = str_replace(env('APP_URL'), '', $value);
}
}

12
app/Models/Agent.php

@ -19,6 +19,18 @@ class Agent extends BaseModel
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)
{
//新增时

8
app/Models/Article.php

@ -8,8 +8,14 @@ class Article extends BaseModel
{
use HasFactory;
public function getImageAttribute($value)
public function getImageAttribute($value): string
{
return $value ? $this->host . $value : '';
}
public function setImageAttribute($value)
{
//修改器里面$this->host变量为空
$this->attributes['image'] = str_replace(env('APP_URL'), '', $value);
}
}

14
app/Models/Channel.php

@ -14,8 +14,20 @@ class Channel extends BaseModel
{
use HasFactory, SoftDeletes;
public function getIconAttribute($value)
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->timestamps = false;
}
public function getIconAttribute($value): string
{
return $value ? $this->host . $value : '';
}
public function setIconAttribute($value)
{
//修改器里面$this->host变量为空
$this->attributes['license_pic'] = str_replace(env('APP_URL'), '', $value);
}
}

10
app/Models/Order.php

@ -28,7 +28,7 @@ class Order extends BaseModel
}
//退款信息
public function getRefundInfoAttribute($value)
public function getRefundInfoAttribute($value): array
{
$value = $value ? json_decode($value, true) : [];
if (!empty($value['pictures']) && is_array($value['pictures'])) {
@ -39,11 +39,17 @@ class Order extends BaseModel
return $value ?? [];
}
public function getPictureAttribute($value)
public function getPictureAttribute($value): string
{
return $value ? $this->host . $value : '';
}
public function setPictureAttribute($value)
{
//修改器里面$this->host变量为空
$this->attributes['picture'] = str_replace(env('APP_URL'), '', $value);
}
public function agentProduct()
{
return $this->belongsTo(AgentProduct::class);

Loading…
Cancel
Save