display a warning message when deleting a client that has an active user

i want to display a warning when deleting a client with an active user. so that the client cannot be deleted if there is an active user with the client. what’s the solution? I need solution as soon as possible, thanks.

I’m using Laravel 8, with PHP 8.1

here’s my code:

ClientController.php

    /**
 * Remove the client, with CLIENT_ID
 *
 * @param  integer $CLIENT_ID
 * @return IlluminateHttpResponse
 */
public function destroy($CLIENT_ID)
{
    $clientName = Client::where('CLIENT_ID',$CLIENT_ID)->first();

    $deleted = $this->clientRepo->delete($CLIENT_ID);

    return $deleted ? redirect()->route('client')->with('alert-success', trans('validation.success_delete', ['name' => 'Client with name '.$clientName["COMPANY_NAME"]])) : back()->withInput()->withErrors([trans('validation.failed_delete', ['name' => 'Client'])]);
}

UserController

/**
 * Activate or Deactivate User, with USER_ID
 *
 * @param  integer $USER_ID
 * @return IlluminateHttpResponse
 */
public function changeActiveStatus($USER_ID,$ADAPT)
{
    $userName = ApiUser::where('USER_ID',$USER_ID)->first();

    $changeStatus = $this->apiUserRepo->changeStatus($USER_ID,$userName["ACTIVE"]);

    if (!empty($ADAPT)){
        return $changeStatus
            ? redirect()->route('user.detail_edit',['USER_ID' => $USER_ID])->with('alert-success', trans('validation.success_change_status', ['name' => 'User status with name '.$userName["USER_NAME"]])): back()->withInput()->withErrors([trans('validation.failed_change_status', ['name' => 'User'])]);
    }

    return $changeStatus
            ? redirect()->route('user')->with('alert-success', trans('validation.success_change_status', ['name' => 'User status with name '.$userName["USER_NAME"]])): back()->withInput()->withErrors([trans('validation.failed_change_status', ['name' => 'User'])]);
}

Examples

  1. I create a Client named PT. Gudang Garam
  2. I create a User with Client at #1, User is Active status
  3. if the client #1 is deleted, it will display an alert if there is an active user, and the client cannot be deleted