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