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