repository = $doctorrequest; parent::__construct(); } /** * Display a list of doctorrequest. * * @return json */ public function index(DoctorrequestUserApiRequest $request) { $doctorrequests = $this->repository ->pushCriteria(new \Lavalite\Doctorrequest\Repositories\Criteria\DoctorrequestUserCriteria()) ->setPresenter('\\Litecms\\Doctorrequest\\Repositories\\Presenter\\DoctorrequestListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); $doctorrequests['code'] = 2000; return response()->json($doctorrequests) ->setStatusCode(200, 'INDEX_SUCCESS'); } /** * Display doctorrequest. * * @param Request $request * @param Model Doctorrequest * * @return Json */ public function show(DoctorrequestUserApiRequest $request, Doctorrequest $doctorrequest) { if ($doctorrequest->exists) { $doctorrequest = $doctorrequest->presenter(); $doctorrequest['code'] = 2001; return response()->json($doctorrequest) ->setStatusCode(200, 'SHOW_SUCCESS');; } else { return response()->json([]) ->setStatusCode(400, 'SHOW_ERROR'); } } /** * Show the form for creating a new doctorrequest. * * @param Request $request * * @return json */ public function create(DoctorrequestUserApiRequest $request, Doctorrequest $doctorrequest) { $doctorrequest = $doctorrequest->presenter(); $doctorrequest['code'] = 2002; return response()->json($doctorrequest) ->setStatusCode(200, 'CREATE_SUCCESS'); } /** * Create new doctorrequest. * * @param Request $request * * @return json */ public function store(DoctorrequestUserApiRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.api'); $doctorrequest = $this->repository->create($attributes); $doctorrequest = $doctorrequest->presenter(); $doctorrequest['code'] = 2004; return response()->json($doctorrequest) ->setStatusCode(201, 'STORE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4004, ])->setStatusCode(400, 'STORE_ERROR'); } } /** * Show doctorrequest for editing. * * @param Request $request * @param Model $doctorrequest * * @return json */ public function edit(DoctorrequestUserApiRequest $request, Doctorrequest $doctorrequest) { if ($doctorrequest->exists) { $doctorrequest = $doctorrequest->presenter(); $doctorrequest['code'] = 2003; return response()-> json($doctorrequest) ->setStatusCode(200, 'EDIT_SUCCESS');; } else { return response()->json([]) ->setStatusCode(400, 'SHOW_ERROR'); } } /** * Update the doctorrequest. * * @param Request $request * @param Model $doctorrequest * * @return json */ public function update(DoctorrequestUserApiRequest $request, Doctorrequest $doctorrequest) { try { $attributes = $request->all(); $doctorrequest->update($attributes); $doctorrequest = $doctorrequest->presenter(); $doctorrequest['code'] = 2005; return response()->json($doctorrequest) ->setStatusCode(201, 'UPDATE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4005, ])->setStatusCode(400, 'UPDATE_ERROR'); } } /** * Remove the doctorrequest. * * @param Request $request * @param Model $doctorrequest * * @return json */ public function destroy(DoctorrequestUserApiRequest $request, Doctorrequest $doctorrequest) { try { $t = $doctorrequest->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('doctorrequest::doctorrequest.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }