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