更新首字母
This commit is contained in:
@@ -59,4 +59,18 @@ class BrandTranslationModel extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(BrandModel::class, 'brand_id');
|
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')]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -128,6 +128,9 @@ class VehicleNewService extends BaseService
|
|||||||
|
|
||||||
Db::beginTransaction();
|
Db::beginTransaction();
|
||||||
try {
|
try {
|
||||||
|
if(empty($params['model'])){
|
||||||
|
$params['model'] = 0;
|
||||||
|
}
|
||||||
$info = $this->create($params);
|
$info = $this->create($params);
|
||||||
if (!$info) {
|
if (!$info) {
|
||||||
throw new BusinessException('提交失败');
|
throw new BusinessException('提交失败');
|
||||||
@@ -253,6 +256,9 @@ class VehicleNewService extends BaseService
|
|||||||
|
|
||||||
Db::beginTransaction();
|
Db::beginTransaction();
|
||||||
try {
|
try {
|
||||||
|
if(empty($params['model'])){
|
||||||
|
$params['model'] = 0;
|
||||||
|
}
|
||||||
$info = $this->update($id, $params);
|
$info = $this->update($id, $params);
|
||||||
if (!$info) {
|
if (!$info) {
|
||||||
throw new BusinessException('提交失败');
|
throw new BusinessException('提交失败');
|
||||||
|
|||||||
Reference in New Issue
Block a user