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