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