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