repository = $doctorrequest; parent::__construct(); } /** * Display a list of doctorrequest. * * @return Response */ public function index(DoctorrequestAdminWebRequest $request) { if ($request->wantsJson()) { $doctorrequests = $this->repository->setPresenter('\\Litecms\\Doctorrequest\\Repositories\\Presenter\\DoctorrequestListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); return response()->json($doctorrequests, 200); } $this ->theme->prependTitle(trans('doctorrequest::doctorrequest.names').' :: '); return $this->theme->of('doctorrequest::admin.doctorrequest.index')->render(); } /** * Display doctorrequest. * * @param Request $request * @param Model $doctorrequest * * @return Response */ public function show(DoctorrequestAdminWebRequest $request, Doctorrequest $doctorrequest) { if (!$doctorrequest->exists) { return response()->view('doctorrequest::admin.doctorrequest.new', compact('doctorrequest')); } Form::populate($doctorrequest); return response()->view('doctorrequest::admin.doctorrequest.show', compact('doctorrequest')); } /** * Show the form for creating a new doctorrequest. * * @param Request $request * * @return Response */ public function create(DoctorrequestAdminWebRequest $request) { $doctorrequest = $this->repository->newInstance([]); Form::populate($doctorrequest); return response()->view('doctorrequest::admin.doctorrequest.create', compact('doctorrequest')); } /** * Create new doctorrequest. * * @param Request $request * * @return Response */ public function store(DoctorrequestAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $doctorrequest = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('doctorrequest::doctorrequest.name')]), 'code' => 204, 'redirect' => trans_url('/admin/doctorrequest/doctorrequest/'.$doctorrequest->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show doctorrequest for editing. * * @param Request $request * @param Model $doctorrequest * * @return Response */ public function edit(DoctorrequestAdminWebRequest $request, Doctorrequest $doctorrequest) { Form::populate($doctorrequest); return response()->view('doctorrequest::admin.doctorrequest.edit', compact('doctorrequest')); } /** * Update the doctorrequest. * * @param Request $request * @param Model $doctorrequest * * @return Response */ public function update(DoctorrequestAdminWebRequest $request, Doctorrequest $doctorrequest) { try { $attributes = $request->all(); $doctorrequest->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('doctorrequest::doctorrequest.name')]), 'code' => 204, 'redirect' => trans_url('/admin/doctorrequest/doctorrequest/'.$doctorrequest->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/doctorrequest/doctorrequest/'.$doctorrequest->getRouteKey()), ], 400); } } /** * Remove the doctorrequest. * * @param Model $doctorrequest * * @return Response */ public function destroy(DoctorrequestAdminWebRequest $request, Doctorrequest $doctorrequest) { try { $t = $doctorrequest->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('doctorrequest::doctorrequest.name')]), 'code' => 202, 'redirect' => trans_url('/admin/doctorrequest/doctorrequest/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/doctorrequest/doctorrequest/'.$doctorrequest->getRouteKey()), ], 400); } } }