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