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