From 7407747294c9f3c395f75d34df36911b652f6c66 Mon Sep 17 00:00:00 2001 From: EnesSacid-Buker <73346401+EnesSacid-Buker@users.noreply.github.com> Date: Fri, 3 Jun 2022 17:57:57 +0300 Subject: [PATCH] Code refactoring. --- app/Abstracts/Factory.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/Abstracts/Factory.php b/app/Abstracts/Factory.php index f633e9b8a..8a42fe0cf 100644 --- a/app/Abstracts/Factory.php +++ b/app/Abstracts/Factory.php @@ -45,7 +45,7 @@ abstract class Factory extends BaseFactory public function company(int $id): static { - Cache::put('factory_company_id', $id, Date::now()->addHour(6)); + Cache::put('state_company_id', $id, Date::now()->addHour(6)); return $this->state([ 'company_id' => $id, @@ -59,17 +59,13 @@ abstract class Factory extends BaseFactory public function setCompany(): void { - $id = Cache::get('factory_company_id'); + $state_id = Cache::get('state_company_id'); - if (! is_null($id)) { - $this->company = company($id); - } else { - $this->company = $this->user->companies()->first(); - } + $this->company = ! is_null($state_id) ? company($state_id) : $this->user->companies()->first(); $this->company->makeCurrent(); - app('url')->defaults(['company_id' => company_id()]); + app('url')->defaults(['company_id' => $this->company->id]); } public function getRawAttribute($key)