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