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