Files
usedcar/app/console/model/BrandTranslationModel.php
2025-05-30 16:58:03 +08:00

76 lines
1.5 KiB
PHP

<?php
namespace app\console\model;
use support\Model;
/**
* BrandTranslationModel
*/
class BrandTranslationModel extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'hs_brand_translation';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
/**
* 模型的数据字段的保存格式。
*
* @var string
*/
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'brand_id', 'locale', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
public function brand()
{
return $this->belongsTo(BrandModel::class, 'brand_id');
}
// 初始化钩子
public static function boot()
{
parent::boot();
// 保存后触发(包括创建和更新)
static::saved(function ($model) {
// 业务逻辑
if($model->locale == 'en'){
BrandModel::updateOrCreate(['id' => $model->brand_id],['letter' => mb_substr($model->name, 0, 1, 'UTF-8')]);
}
});
}
}