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