Commit 20a5e93d authored by Marcos Roberto Silva's avatar Marcos Roberto Silva

Validacao do cadastro de usuario

parent 76b62491
......@@ -3,11 +3,13 @@
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\DocumentoPessoa;
use App\Repositories\Contracts\UserRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Validator;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator as FacadesValidator;
class UserController extends Controller
{
......@@ -27,9 +29,11 @@ class UserController extends Controller
*/
public function index(Request $request)
{
$columnList = ['id' => '#', 'nome' => trans('agendamento.name'), 'email' => trans('agendamento.email'),
$columnList = [
'id' => '#', 'nome' => trans('agendamento.name'), 'email' => trans('agendamento.email'),
'cpf' => trans('agendamento.cpf'), 'sobrenome' => trans('agendamento.sobrenome'), 'telefone' => trans('agendamento.telefone'),
'data_nascimento' => trans('agendamento.data_nascimento')];
'data_nascimento' => trans('agendamento.data_nascimento')
];
$page = trans('agendamento.user_list');
......@@ -48,8 +52,10 @@ class UserController extends Controller
(object) ['url' => '', 'title' => trans('agendamento.list', ['page' => $page])],
];
return view('admin.' . $routeName . '.index', ['list' => $list, 'search' => $search,
'page' => $page, 'routeName' => $routeName, 'columnList' => $columnList, 'breadcrumb' => $breadcrumb]);
return view('admin.' . $routeName . '.index', [
'list' => $list, 'search' => $search,
'page' => $page, 'routeName' => $routeName, 'columnList' => $columnList, 'breadcrumb' => $breadcrumb
]);
}
/**
......@@ -71,7 +77,6 @@ class UserController extends Controller
];
return view('admin.' . $routeName . '.create', ['page' => $page, 'page_create' => $page_create, 'routeName' => $routeName, 'breadcrumb' => $breadcrumb]);
}
/**
......@@ -85,7 +90,7 @@ class UserController extends Controller
$data = $request->all();
$data['password'] = Hash::make($data['password']);
Validator::make($data, [
FacadesValidator::make($data, [
'name' => 'required|string|max:255',
'sobrenome' => 'required|string',
'email' => 'required|string|email|max:255|unique:users',
......@@ -95,16 +100,17 @@ class UserController extends Controller
'data_nascimento' => 'required',
]);
if ($this->model->create($data)) {
$documentosPessoa = DocumentoPessoa::where('cpf', $data['cpf'])->first();
if ($documentosPessoa) {
$this->model->create($data);
session()->flash('msg', trans('agendamento.record_added_successfully'));
session()->flash('status', 'success'); // success error notification
return redirect()->back();
} else {
} elseif ($documentosPessoa == null) {
session()->flash('msg', trans('agendamento.error_adding_registry'));
session()->flash('status', 'error'); // success error notification
return redirect()->back();
}
}
/**
......@@ -165,7 +171,6 @@ class UserController extends Controller
return view('admin.' . $routeName . '.edit', ['page' => $page, 'page2' => $page2, 'register' => $register, 'routeName' => $routeName, 'breadcrumb' => $breadcrumb]);
}
return redirect()->route($routeName . '.index');
}
/**
......@@ -184,7 +189,7 @@ class UserController extends Controller
unset($data['password']);
}
Validator::make($data, [
FacadesValidator::make($data, [
'name' => 'required|string|max:255',
'sobrenome' => 'required|string',
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')->ignore($id)],
......@@ -194,6 +199,8 @@ class UserController extends Controller
'data_nascimento' => 'required',
]);
if ($this->model->update($data, $id)) {
session()->flash('msg', trans('agendamento.successfully_edited_record'));
session()->flash('status', 'success'); // success error notification
......
......@@ -41,5 +41,8 @@ class AppServiceProvider extends ServiceProvider
$this->app->bind('App\Repositories\Contracts\AgendamentoRepositoryInterface',
'App\Repositories\Eloquent\AgendamentoRepository');
$this->app->bind('App\Repositories\Contracts\DocumentoPessoaRepositoryInterface',
'App\Repositories\Eloquent\DocumentoPessoaRepository');
}
}
<?php
namespace App\Repositories\Contracts;
interface DocumentoPessoaRepositoryInterface
{
public function all(string $column = 'cpf');
public function paginate(int $paginate = 10, string $column = 'id', string $order = 'ASC');
public function findWhereLike(array $columns, string $search, string $column = 'id', string $order = 'ASC');
public function create(array $data);
public function find(int $id);
public function update(array $data, int $id);
public function delete(int $id);
}
......@@ -62,6 +62,17 @@ abstract class AbstractRepository
}
}
public function findWhere($column, $valor)
{
return $this->model->where($column, $valor)
->get();
}
public function findWhereFirst($column, $valor)
{
return $this->model->where($column, $valor)->first();
}
protected function resolveModel()
{
return app($this->model);
......
<?php
namespace App\Repositories\Eloquent;
use App\Repositories\Contracts\DocumentoPessoaRepositoryInterface;
use App\Models\DocumentoPessoa;
use Illuminate\Support\Facades\Hash;
class DocumentoPessoaRepository extends AbstractRepository implements DocumentoPessoaRepositoryInterface
{
protected $model = DocumentoPessoa::class;
}
......@@ -54,4 +54,5 @@ return [
'data_nascimento'=>'Date of birth',
'telefone'=>'Phone',
'sobrenome'=>'Surname',
'next'=>'Next',
];
......@@ -52,4 +52,5 @@ return [
'data_nascimento'=>'Data de nascimento',
'telefone'=>'Telefone',
'sobrenome'=>'Sobrenome',
'next'=>'Próximo',
];
\ No newline at end of file
......@@ -12,7 +12,8 @@
@form(['action'=>route($routeName.'.store'),'method'=>'POST'])
@include('admin.'.$routeName.'.form')
<button class="btn btn-primary btn-lg" style="float: right">@lang('agendamento.add')</button>
@csrf
<button class="btn btn-primary btn-lg" style="float: right">@lang('agendamento.next')</button>
@endform
@endpage
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment