更新首字母
This commit is contained in:
@@ -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')]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user