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