middleware('web'); $this->middleware('auth:admin.web'); $this->setupTheme(config('theme.themes.admin.theme'), config('theme.themes.admin.layout')); $this->repository = $updates; parent::__construct(); } /** * Display a list of updates. * * @return Response */ public function index(UpdatesAdminWebRequest $request) { $pageLimit = $request->input('pageLimit'); if ($request->wantsJson()) { $updates = $this->repository ->pushCriteria(new \Litecms\Update\Repositories\Criteria\UpdatesAdminCriteria()) ->setPresenter('\\Litecms\\Update\\Repositories\\Presenter\\UpdatesListPresenter') ->scopeQuery(function ($query) { return $query->orderBy('id', 'DESC'); })->paginate($pageLimit); $updates['recordsTotal'] = $updates['meta']['pagination']['total']; $updates['recordsFiltered'] = $updates['meta']['pagination']['total']; $updates['request'] = $request->all(); return response()->json($updates, 200); } $this ->theme->prependTitle(trans('update::updates.names').' :: '); return $this->theme->of('update::admin.updates.index')->render(); } /** * Display updates. * * @param Request $request * @param Model $updates * * @return Response */ public function show(UpdatesAdminWebRequest $request, Updates $updates) { if (!$updates->exists) { return response()->view('update::admin.updates.new', compact('updates')); } Form::populate($updates); return response()->view('update::admin.updates.show', compact('updates')); } /** * Show the form for creating a new updates. * * @param Request $request * * @return Response */ public function create(UpdatesAdminWebRequest $request) { $updates = $this->repository->newInstance([]); Form::populate($updates); return response()->view('update::admin.updates.create', compact('updates')); } /** * Create new updates. * * @param Request $request * * @return Response */ public function store(UpdatesAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $updates = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('update::updates.name')]), 'code' => 204, 'redirect' => trans_url('/admin/update/updates/'.$updates->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show updates for editing. * * @param Request $request * @param Model $updates * * @return Response */ public function edit(UpdatesAdminWebRequest $request, Updates $updates) { Form::populate($updates); return response()->view('update::admin.updates.edit', compact('updates')); } /** * Update the updates. * * @param Request $request * @param Model $updates * * @return Response */ public function update(UpdatesAdminWebRequest $request, Updates $updates) { try { $attributes = $request->all(); $updates->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('update::updates.name')]), 'code' => 204, 'redirect' => trans_url('/admin/update/updates/'.$updates->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/update/updates/'.$updates->getRouteKey()), ], 400); } } /** * Remove the updates. * * @param Model $updates * * @return Response */ public function destroy(UpdatesAdminWebRequest $request, Updates $updates) { try { $t = $updates->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('update::updates.name')]), 'code' => 202, 'redirect' => trans_url('/admin/update/updates/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/update/updates/'.$updates->getRouteKey()), ], 400); } } }