repository = $trialpackage; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Thaolx\TrialPackage\Repositories\Criteria\TrialpackageCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(TrialpackageRequest $request) { $trialpackages = $this->repository->scopeQuery(function ($query) { return $query->orderBy('id', 'DESC'); })->paginate(); $this->theme->prependTitle(trans('trial_package::trialpackage.names')); return $this->theme->of('trial_package::public.trialpackage.index', compact('trialpackages'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Trialpackage $trialpackage * * @return Response */ public function show(TrialpackageRequest $request, Trialpackage $trialpackage) { Form::populate($trialpackage); $this->theme->prependTitle(trans('trial_package::trialpackage.names')); return $this->theme->of('trial_package::public.trialpackage.show', compact('trialpackage'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(TrialpackageRequest $request) { $trialpackage = $this->repository->newInstance([]); Form::populate($trialpackage); $this->theme->prependTitle(trans('app.create') . ' ' . trans('trial_package::trialpackage.names')); return $this->theme->of('trial_package::public.trialpackage.create', compact('trialpackage'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(TrialpackageRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $trialpackage = $this->repository->create($attributes); return redirect(trans_url('trialpackage')) ->with('message', trans('messages.success.created', ['Module' => trans('trial_package::trialpackage.name')])) ->with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Trialpackage $trialpackage * * @return Response */ public function edit(TrialpackageRequest $request, Trialpackage $trialpackage) { Form::populate($trialpackage); $this->theme->prependTitle(trans('app.edit') . ' ' . trans('trial_package::trialpackage.names')); return $this->theme->of('trial_package::public.trialpackage.edit', compact('trialpackage'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Trialpackage $trialpackage * * @return Response */ public function update(TrialpackageRequest $request, Trialpackage $trialpackage) { try { $this->repository->update($request->all(), $trialpackage->getRouteKey()); return redirect(trans_url('trialpackage')) ->with('message', trans('messages.success.updated', ['Module' => trans('trial_package::trialpackage.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(TrialpackageRequest $request, Trialpackage $trialpackage) { try { $t = $trialpackage->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('trial_package::trialpackage.name')]), 'code' => 202, 'redirect' => trans_url('/trialpackage'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/trialpackage/'.$trialpackage->getRouteKey()), ], 400); } } }