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