Debugging company delete issues

This commit is contained in:
David Bomba 2020-06-09 19:29:41 +10:00
parent 32fde9c082
commit e35b1b6871
2 changed files with 4 additions and 2 deletions

View File

@ -466,6 +466,7 @@ class CompanyController extends BaseController
*/ */
public function destroy(DestroyCompanyRequest $request, Company $company) public function destroy(DestroyCompanyRequest $request, Company $company)
{ {
$company_count = $company->account->companies->count(); $company_count = $company->account->companies->count();
$account = $company->account; $account = $company->account;
@ -482,11 +483,13 @@ class CompanyController extends BaseController
} else { } else {
$company_id = $company->id; $company_id = $company->id;
$company->delete(); $company->delete();
//If we are deleting the default companies, we'll need to make a new company the default. //If we are deleting the default companies, we'll need to make a new company the default.
if ($account->default_company_id == $company_id) { if ($account->default_company_id == $company_id) {
$new_default_company = Company::whereAccountId($account->id)->first(); $new_default_company = Company::whereAccountId($account->id)->first();
$account->default_company_id = $new_default_company->id; $account->default_company_id = $new_default_company->id;
$account->save(); $account->save();

View File

@ -12,7 +12,6 @@
namespace App\Http\Requests\Company; namespace App\Http\Requests\Company;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Models\Company;
class DestroyCompanyRequest extends Request class DestroyCompanyRequest extends Request
{ {