Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 \Illuminate\Http\Response
 */
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 \Illuminate\Http\Response
 */
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'])]);
}

MySQL Query

SELECT CLIENT.CLIENT_ID , CLIENT.COMPANY_NAME, USER.USER_NAME
FROM SMS_API_V2_NEW.CLIENT
LEFT JOIN SMS_API_V2_NEW.`USER`
ON CLIENT.CLIENT_ID = USER.CLIENT_ID
WHERE USER.USER_NAME IS NOT NULL;

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
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda