后台会员管理

This commit is contained in:
TL 2022-07-01 15:49:05 +08:00
parent 77057227d3
commit d0b2ccfa20
3 changed files with 3 additions and 4 deletions

View File

@ -40,9 +40,8 @@ class CustomerController extends Controller
{ {
$data = $request->only(['email', 'name', 'password', 'status', 'customer_group_id']); $data = $request->only(['email', 'name', 'password', 'status', 'customer_group_id']);
$customer = CustomerService::create($data); $customer = CustomerService::create($data);
$customer->load('group');
return json_success('创建成功!', $customer); return json_success('创建成功!', new CustomerResource($customer));
} }
public function edit(Request $request, Customer $customer) public function edit(Request $request, Customer $customer)

View File

@ -21,7 +21,7 @@ class CustomerResource extends JsonResource
'status' => $this->status ? '启用' : '禁用', 'status' => $this->status ? '启用' : '禁用',
'avatar' => image_resize($this->avatar), 'avatar' => image_resize($this->avatar),
'from' => $this->from, 'from' => $this->from,
'customer_group_name' => $this->customer_group_name ?? $this->group->description->name, 'customer_group_name' => $this->customer_group_name ?? $this->customerGroup->description->name,
'edit' => admin_route('customers.edit', $this->id), 'edit' => admin_route('customers.edit', $this->id),
'delete' => admin_route('customers.destroy', $this->id), 'delete' => admin_route('customers.destroy', $this->id),
]; ];

View File

@ -23,7 +23,7 @@ class Customer extends Authenticatable
return $this->hasMany(Address::class); return $this->hasMany(Address::class);
} }
public function group(): BelongsTo public function customerGroup(): BelongsTo
{ {
return $this->belongsTo(CustomerGroup::class); return $this->belongsTo(CustomerGroup::class);
} }