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