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