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