repository = $trialpackage; parent::__construct(); } /** * Display a list of trialpackage. * * @return Response */ public function index(TrialpackageRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('trial_package::trialpackage.names')); return $this->theme->of('trial_package::admin.trialpackage.index')->render(); } /** * Display a list of trialpackage. * * @return Response */ public function getJson(TrialpackageRequest $request) { $pageLimit = $request->input('pageLimit'); $trialpackages = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Thaolx\\TrialPackage\\Repositories\\Presenter\\TrialpackageListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $trialpackages['recordsTotal'] = $trialpackages['meta']['pagination']['total']; $trialpackages['recordsFiltered'] = $trialpackages['meta']['pagination']['total']; $trialpackages['request'] = $request->all(); return response()->json($trialpackages, 200); } /** * Display trialpackage. * * @param Request $request * @param Model $trialpackage * * @return Response */ public function show(TrialpackageRequest $request, Trialpackage $trialpackage) { if (!$trialpackage->exists) { return response()->view('trial_package::admin.trialpackage.new', compact('trialpackage')); } Form::populate($trialpackage); return response()->view('trial_package::admin.trialpackage.show', compact('trialpackage')); } /** * Show the form for creating a new trialpackage. * * @param Request $request * * @return Response */ public function create(TrialpackageRequest $request) { $trialpackage = $this->repository->newInstance([]); Form::populate($trialpackage); return response()->view('trial_package::admin.trialpackage.create', compact('trialpackage')); } /** * Create new trialpackage. * * @param Request $request * * @return Response */ public function store(TrialpackageRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $trialpackage = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('trial_package::trialpackage.name')]), 'code' => 204, 'redirect' => trans_url('/admin/trial_package/trialpackage/'.$trialpackage->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show trialpackage for editing. * * @param Request $request * @param Model $trialpackage * * @return Response */ public function edit(TrialpackageRequest $request, Trialpackage $trialpackage) { Form::populate($trialpackage); return response()->view('trial_package::admin.trialpackage.edit', compact('trialpackage')); } /** * Update the trialpackage. * * @param Request $request * @param Model $trialpackage * * @return Response */ public function update(TrialpackageRequest $request, Trialpackage $trialpackage) { try { $attributes = $request->all(); $trialpackage->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('trial_package::trialpackage.name')]), 'code' => 204, 'redirect' => trans_url('/admin/trial_package/trialpackage/'.$trialpackage->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/trial_package/trialpackage/'.$trialpackage->getRouteKey()), ], 400); } } /** * Remove the trialpackage. * * @param Model $trialpackage * * @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('/admin/trial_package/trialpackage/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/trial_package/trialpackage/'.$trialpackage->getRouteKey()), ], 400); } } }