会员管理
This commit is contained in:
parent
90d72f2851
commit
77057227d3
|
|
@ -40,8 +40,9 @@ 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('创建成功!', new CustomerResource($customer));
|
return json_success('创建成功!', $customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(Request $request, Customer $customer)
|
public function edit(Request $request, Customer $customer)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class CustomerRequest extends FormRequest
|
||||||
'name' => 'required|max:64',
|
'name' => 'required|max:64',
|
||||||
'email' => 'required|email:rfc,dns|unique:customers',
|
'email' => 'required|email:rfc,dns|unique:customers',
|
||||||
'password' => 'required|max:64',
|
'password' => 'required|max:64',
|
||||||
'customer_group_id' => 'required|unique:customer_groups',
|
'customer_group_id' => 'required|exists:customer_groups,id',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,
|
'customer_group_name' => $this->customer_group_name ?? $this->group->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),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@
|
||||||
namespace Beike\Models;
|
namespace Beike\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
|
|
||||||
|
|
@ -20,4 +22,9 @@ class Customer extends Authenticatable
|
||||||
{
|
{
|
||||||
return $this->hasMany(Address::class);
|
return $this->hasMany(Address::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function group(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(CustomerGroup::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue