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