/** * Show page (get). * * @Get("show/{id}", as="memo.show") * * @param string $id * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function getShow($id) { $memo = $this->memo->find($id); if (!isset($memo)) { abort(404); } return view('memos.show', compact('memo')); }
/** * Delete page (post). * * @Post("delete/{id}", as="user.memo.delete") * * @param string $id * * @return \Illuminate\Http\RedirectResponse * * @throws \Exception */ public function postDelete($id) { $memo = $this->memo->find($id); if (!isset($memo)) { abort(404); } if ($memo->user_id !== $this->user_id) { return redirect('user/memo')->with('message', 'そのメモはあなたのメモではありません。'); } $memo->delete(); return redirect('user/memo')->with('message', '削除しました。'); }
/** * memo/show API. * * @Any("show", as="api.memo.show") * * @return \Illuminate\Http\JsonResponse */ public function anyShow() { try { $id = $this->request('id', null); if (is_int($id)) { $id = (string) $id; } if (empty($id) || !is_string($id)) { throw new RuntimeException('id is empty.'); } $memo = $this->memo->find(intval($id)); if (!isset($memo)) { throw new RuntimeException('Memo not found.'); } return $this->onSuccess($memo->toArray()); } catch (Exception $e) { return $this->onError($e); } }