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