sneha #72

Merged
Sneha.Yadav merged 2 commits from sneha into main 2025-04-08 08:19:38 +00:00
2 changed files with 31 additions and 0 deletions

View File

@@ -650,4 +650,34 @@ class UsersController extends Controller
], 500);
}
}
public function UserByCustomerId($customerId)
{
try {
$users = User::with('customer:id,name')
->where('customer_id', $customerId)
->get()
->map(function ($user) {
$userArray = $user->toArray();
unset($userArray['customer']);
$userArray['customer_name'] = optional($user->customer)->name;
return $userArray;
});
if ($users->isEmpty()) {
return response()->json(['message' => 'No users found for this customer ID'], 404);
}
return jsonResponseWithSuccessMessage('Users fetched successfully', [
'users' => $users
]);
} catch (Exception $e) {
Log::error("An error occurred in fetching users by customer ID: " . $e->getMessage());
return jsonResponseWithErrorMessage($e->getMessage(), 500);
}
}
}

View File

@@ -46,6 +46,7 @@ Route::post('/users-delete', [UsersController::class, 'delete']);
Route::get('/activate/{id}', [UsersController::class, 'activate'])->name('activate.user');
Route::post('/users-login', [UsersController::class, 'loginUser']);
Route::post('/users-customer-list', [UsersController::class, 'userlistCustomer'])->name('usertList.customer');
Route::get('/users/{customer_id}', [UsersController::class, 'UserByCustomerId'])->name('usertList.customerId');
//******************************************************* Device API********************************************************
Route::post('/device/create-or-update', [DeviceController::class, 'createOrUpdateDevice'])->name('device.create-or-update');