repository = $subscription; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\B2buy\Service\Repositories\Criteria\SubscriptionResourceCriteria::class); } /** * Display a list of subscription. * * @return Response */ public function index(SubscriptionRequest $request) { return $this->repository ->setPresenter(\B2buy\Service\Repositories\Presenter\SubscriptionPresenter::class) ->paginate(); } /** * Display subscription. * * @param Request $request * @param Model $subscription * * @return Response */ public function show(SubscriptionRequest $request, Subscription $subscription) { return $subscription->setPresenter(\B2buy\Service\Repositories\Presenter\SubscriptionListPresenter::class); ; } /** * Create new subscription. * * @param Request $request * * @return Response */ public function store(SubscriptionRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('service::subscription.name')]); $code = 204; $status = 'success'; $url = guard_url('service/subscription/' . $subscription->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('service/subscription'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the subscription. * * @param Request $request * @param Model $subscription * * @return Response */ public function update(SubscriptionRequest $request, Subscription $subscription) { try { $data = $request->all(); $subscription->update($data); $message = trans('messages.success.updated', ['Module' => trans('service::subscription.name')]); $code = 204; $status = 'success'; $url = guard_url('service/subscription/' . $subscription->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('service/subscription/' . $subscription->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the subscription. * * @param Model $subscription * * @return Response */ public function destroy(SubscriptionRequest $request, Subscription $subscription) { try { $subscription->delete(); $message = trans('messages.success.deleted', ['Module' => trans('service::subscription.name')]); $code = 202; $status = 'success'; $url = guard_url('service/subscription/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('service/subscription/' . $subscription->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }