/** * Get post body through ajax or redirect to 404. * * @param Request $request * @param string $id format: post-{id} * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View */ public function body(Request $request, $id) { if ($request->ajax()) { return response()->json(['body' => $this->blog->body($id)]); } else { return view('errors.404'); } }