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