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