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