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