update
This commit is contained in:
@@ -44,6 +44,30 @@ class ServiceController extends Controller
|
||||
return response()->json(['error' => false, 'data' => $service]);
|
||||
}
|
||||
|
||||
public function bulkAction(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'ids' => 'required|array|min:1',
|
||||
'ids.*' => 'integer|distinct|exists:services,id',
|
||||
'action' => 'required|in:activate,suspend,cancel,detach-customer',
|
||||
]);
|
||||
|
||||
$updates = match ($data['action']) {
|
||||
'activate' => ['status' => 'active', 'suspended_at' => null, 'cancelled_at' => null],
|
||||
'suspend' => ['status' => 'suspended', 'suspended_at' => now()],
|
||||
'cancel' => ['status' => 'cancelled', 'cancelled_at' => now()],
|
||||
'detach-customer' => ['customer_id' => null],
|
||||
};
|
||||
|
||||
$updated = Service::whereIn('id', $data['ids'])->update($updates);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => "Đã cập nhật {$updated} dịch vụ.",
|
||||
'data' => ['updated' => $updated],
|
||||
]);
|
||||
}
|
||||
|
||||
public function detachCustomer(int $id): JsonResponse
|
||||
{
|
||||
$service = Service::findOrFail($id);
|
||||
|
||||
Reference in New Issue
Block a user