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