Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!