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