repository = $addons; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Addon\Repositories\Criteria\AddonsResourceCriteria::class); } /** * Display a list of addons. * * @return Response */ public function index(AddonsRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litecms\Addon\Repositories\Presenter\AddonsPresenter::class) ->$function(); } $addons = $this->repository->paginate(); return $this->response->title(trans('addon::addons.names')) ->view('addon::addons.index', true) ->data(compact('addons')) ->output(); } /** * Display addons. * * @param Request $request * @param Model $addons * * @return Response */ public function show(AddonsRequest $request, Addons $addons) { if ($addons->exists) { $view = 'addon::addons.show'; } else { $view = 'addon::addons.new'; } return $this->response->title(trans('app.view') . ' ' . trans('addon::addons.name')) ->data(compact('addons')) ->view($view, true) ->output(); } /** * Show the form for creating a new addons. * * @param Request $request * * @return Response */ public function create(AddonsRequest $request) { $addons = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('addon::addons.name')) ->view('addon::addons.create', true) ->data(compact('addons')) ->output(); } /** * Create new addons. * * @param Request $request * * @return Response */ public function store(AddonsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $addons = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('addon::addons.name')])) ->code(204) ->status('success') ->url(guard_url('addon/addons/' . $addons->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/addon/addons')) ->redirect(); } } /** * Show addons for editing. * * @param Request $request * @param Model $addons * * @return Response */ public function edit(AddonsRequest $request, Addons $addons) { return $this->response->title(trans('app.edit') . ' ' . trans('addon::addons.name')) ->view('addon::addons.edit', true) ->data(compact('addons')) ->output(); } /** * Update the addons. * * @param Request $request * @param Model $addons * * @return Response */ public function update(AddonsRequest $request, Addons $addons) { try { $attributes = $request->all(); $addons->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('addon::addons.name')])) ->code(204) ->status('success') ->url(guard_url('addon/addons/' . $addons->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('addon/addons/' . $addons->getRouteKey())) ->redirect(); } } /** * Remove the addons. * * @param Model $addons * * @return Response */ public function destroy(AddonsRequest $request, Addons $addons) { try { $addons->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('addon::addons.name')])) ->code(202) ->status('success') ->url(guard_url('addon/addons/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('addon/addons/' . $addons->getRouteKey())) ->redirect(); } } /** * Remove multiple addons. * * @param Model $addons * * @return Response */ public function delete(AddonsRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('addon::addons.name')])) ->status("success") ->code(202) ->url(guard_url('addon/addons')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/addon/addons')) ->redirect(); } } /** * Restore deleted addons. * * @param Model $addons * * @return Response */ public function restore(AddonsRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('addon::addons.name')])) ->status("success") ->code(202) ->url(guard_url('/addon/addons')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/addon/addons/')) ->redirect(); } } }