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