erp/app/Models/Goods.php

53 lines
932 B
PHP
Raw Normal View History

<?php
namespace App\Models;
2022-07-28 13:46:08 +08:00
use App\Models\traits\Filter;
class Goods extends Model
{
2022-07-28 13:46:08 +08:00
use Filter;
2022-07-28 16:06:15 +08:00
//查询字段
public $fieldSearchable = [
2022-07-28 17:08:05 +08:00
'goods_title',
2022-07-28 16:06:15 +08:00
'type_id',
'brand_id',
];
2022-08-09 20:05:19 +08:00
protected $fillable = [
'title',
'img_url',
'type_id',
'brand_id',
'goods_code',
];
2022-08-03 16:41:15 +08:00
public function getImgUrlAttribute($value)
{
2022-08-17 16:21:07 +08:00
if (0 === strpos($value, 'ju8hn6/erp/shop')) {
$value = config('filesystems.disks.aliyun.url') . $value;
}
return $value;
}
2022-07-28 13:46:08 +08:00
/**
* 多规格
*/
public function skus()
{
return $this->hasMany(GoodsSku::class, 'goods_id');
}
public function brand()
{
2023-04-03 15:41:14 +08:00
return $this->belongsTo(GoodsBrand::class, 'brand_id', 'id');
2022-07-28 13:46:08 +08:00
}
2022-07-28 13:46:08 +08:00
public function type()
{
2023-04-03 15:41:14 +08:00
return $this->belongsTo(GoodsType::class, 'type_id', 'id');
2022-07-28 13:46:08 +08:00
}
}