59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Modules\SystemTool\Models\SysFileModel;
|
|
|
|
/**
|
|
* 小程序首页促销推荐卡片
|
|
*/
|
|
class HomePromoModel extends Model
|
|
{
|
|
/** 状态:停用 */
|
|
public const int STATUS_DISABLED = 0;
|
|
/** 状态:正常 */
|
|
public const int STATUS_NORMAL = 1;
|
|
|
|
protected $table = 'mini_home_promo';
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $fillable = [
|
|
'title',
|
|
'sub_title',
|
|
'image_id',
|
|
'link',
|
|
'sort',
|
|
'status',
|
|
];
|
|
|
|
protected $casts = [
|
|
'image_id' => 'integer',
|
|
'sort' => 'integer',
|
|
'status' => 'integer',
|
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
|
'updated_at' => 'datetime:Y-m-d H:i:s',
|
|
];
|
|
|
|
protected $appends = ['image_url'];
|
|
|
|
protected $with = ['image'];
|
|
|
|
/**
|
|
* 关联图片
|
|
*/
|
|
public function image(): HasOne
|
|
{
|
|
return $this->hasOne(SysFileModel::class, 'id', 'image_id');
|
|
}
|
|
|
|
/**
|
|
* 图片链接
|
|
*/
|
|
public function getImageUrlAttribute(): ?string
|
|
{
|
|
return $this->image?->preview_url;
|
|
}
|
|
}
|