更新首字母

This commit is contained in:
2025-05-30 14:19:28 +08:00
parent 628892dde6
commit 02ee7fda9c
2 changed files with 20 additions and 0 deletions
@@ -59,4 +59,18 @@ class BrandTranslationModel extends Model
{
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->id],['letter' => mb_substr($model->name, 0, 1, 'UTF-8')]);
}
});
}
}