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