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) { return $this->repository ->setPresenter(\Bixo\Listing\Repositories\Presenter\ReferralPresenter::class) ->paginate(); } /** * Display referral. * * @param Request $request * @param Model $referral * * @return Response */ public function show(ReferralRequest $request, Referral $referral) { return $referral->setPresenter(\Bixo\Listing\Repositories\Presenter\ReferralListPresenter::class); ; } /** * Create new referral. * * @param Request $request * * @return Response */ public function store(ReferralRequest $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('listing::referral.name')]); $code = 204; $status = 'success'; $url = guard_url('listing/referral/' . $referral->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('listing/referral'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the referral. * * @param Request $request * @param Model $referral * * @return Response */ public function update(ReferralRequest $request, Referral $referral) { try { $data = $request->all(); $referral->update($data); $message = trans('messages.success.updated', ['Module' => trans('listing::referral.name')]); $code = 204; $status = 'success'; $url = guard_url('listing/referral/' . $referral->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('listing/referral/' . $referral->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the referral. * * @param Model $referral * * @return Response */ public function destroy(ReferralRequest $request, Referral $referral) { try { $referral->delete(); $message = trans('messages.success.deleted', ['Module' => trans('listing::referral.name')]); $code = 202; $status = 'success'; $url = guard_url('listing/referral/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('listing/referral/' . $referral->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); } }