form = SubscriptionForm::setAttributes()->toArray(); $this->modules = $this->modules(config('ebuy.subscription.modules'), 'subscription', guard_url('subscription')); $this->repository = $subscription; } /** * Display a list of subscription. * * @return Response */ public function index(SubscriptionRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(SubscriptionResourceFilter::class) ->setPresenter(SubscriptionListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('subscription::subscription.names')) ->view('subscription::subscription.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display subscription. * * @param Request $request * @param Model $subscription * * @return Response */ public function show(SubscriptionRequest $request, SubscriptionRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('subscription::subscription.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('subscription::subscription.show') ->output(); } /** * Show the form for creating a new subscription. * * @param Request $request *x * @return Response */ public function create(SubscriptionRequest $request, SubscriptionRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('subscription::subscription.name')) ->view('subscription::subscription.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new subscription. * * @param Request $request * * @return Response */ public function store(SubscriptionRequest $request, SubscriptionRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('subscription::subscription.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('subscription/subscription/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/subscription/subscription')) ->redirect(); } } /** * Show subscription for editing. * * @param Request $request * @param Model $subscription * * @return Response */ public function edit(SubscriptionRequest $request, SubscriptionRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('subscription::subscription.name')) ->view('subscription::subscription.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the subscription. * * @param Request $request * @param Model $subscription * * @return Response */ public function update(SubscriptionRequest $request, SubscriptionRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('subscription::subscription.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('subscription/subscription/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('subscription/subscription/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the subscription. * * @param Model $subscription * * @return Response */ public function destroy(SubscriptionRequest $request, SubscriptionRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('subscription::subscription.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('subscription/subscription/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('subscription/subscription/' . $repository->getRouteKey())) ->redirect(); } } }