authorize(); event(new AccountUpdating($this->model, $this->request)); \DB::transaction(function () { $this->model->update($this->request->all()); // Set default account if ($this->request['default_account']) { setting()->set('default.account', $this->model->id); setting()->save(); } }); event(new AccountUpdated($this->model, $this->request)); return $this->model; } /** * Determine if this action is applicable. */ public function authorize(): void { $relationships = $this->getRelationships(); if (!$this->request->get('enabled') && ($this->model->id == setting('default.account'))) { $relationships[] = strtolower(trans_choice('general.companies', 1)); $message = trans('messages.warning.disabled', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]); throw new \Exception($message); } if (!$relationships) { return; } if ($this->model->currency_code != $this->request->get('currency_code')) { $message = trans('messages.warning.disable_code', ['name' => $this->model->name, 'text' => implode(', ', $relationships)]); throw new \Exception($message); } } public function getRelationships(): array { $rels = [ 'transactions' => 'transactions', ]; return $this->countRelationships($this->model, $rels); } }