This commit is contained in:
Edward Yang 2022-08-18 17:24:02 +08:00
parent 35c464f47e
commit 36208c0c35
2 changed files with 18 additions and 3 deletions

View File

@ -18,7 +18,7 @@ class Brand extends Base
{ {
use HasFactory; use HasFactory;
protected $fillable = ['name', 'country_id', 'first', 'logo', 'code', 'sort_order', 'status']; protected $fillable = ['name', 'first', 'logo', 'sort_order', 'status'];
public function products() :HasMany public function products() :HasMany
{ {

View File

@ -31,7 +31,14 @@ class BrandRepo
*/ */
public static function create($data) public static function create($data)
{ {
return Brand::query()->create($data); $brandData = [
'name' => $data['name'] ?? '',
'first' => $data['first'] ?? '',
'logo' => $data['logo'] ?? '',
'sort_order' => (int)($data['sort_order'] ?? 0),
'status' => (bool)($data['status'] ?? 1),
];
return Brand::query()->create($brandData);
} }
/** /**
@ -48,7 +55,15 @@ class BrandRepo
if (!$brand) { if (!$brand) {
throw new Exception("品牌id $brand 不存在"); throw new Exception("品牌id $brand 不存在");
} }
$brand->update($data);
$brandData = [
'name' => $data['name'] ?? '',
'first' => $data['first'] ?? '',
'logo' => $data['logo'] ?? '',
'sort_order' => (int)($data['sort_order'] ?? 0),
'status' => (bool)($data['status'] ?? 1),
];
$brand->update($brandData);
return $brand; return $brand;
} }