currentUser(); $goal_repo = new GoalRepository(); $goal = $goal_repo->get((int)$request->param(0)); if (!$goal) { throw HTTPException::factory(404); } $account = (new AccountRepository())->get((int)$goal->account_id); if (!$account || (int)$account->user_id !== (int)$user->id) { throw HTTPException::factory(404); } $goal_repo->delete($goal->id); return $this->json(['success' => true]); } /** * @return object * @throws HTTPException|MyException */ protected function currentUser(): object { $auth_user = Auth::instance()->getUser(); $user = (new UserRepository())->getByLogin($auth_user['login']); if (!$user) { throw HTTPException::factory(404); } return $user; } }