Skip to content

Commit

Permalink
implement update user
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfariasdev committed Aug 12, 2024
1 parent 3054837 commit 27affe5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function boot(): void
Gate::define('view-dashboard-usuarios', function ($user) {
return $user->isAdmin() || $user->isEmpresa();
});

Gate::define('edit-dashboard-usuarios', function ($user) {
return $user->isAdmin();
});
//
}
}
5 changes: 4 additions & 1 deletion app/Services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ public function updateUsuario(Request $request, $id)
'name' => 'required|string|min:3|max:255',
'email' => 'required|email|unique:users,email,' . $user->id, // Verifica se o email é único, ignorando o email atual do usuário
'password' => 'nullable|min:6|confirmed',
'type' => 'required|string|in:Admin,Empresa,Funcionario,Convidado',
'type' => 'nullable|string|in:Admin,Empresa,Funcionario,Convidado',
]);

$user->name = $request->input('name');
$user->email = $request->input('email');

if ($request->filled('type')) {
$user->type = $request->input('type');
}

if ($request->filled('password')) {
$user->password = Hash::make($request->input('password'));
Expand Down
1 change: 1 addition & 0 deletions resources/views/components/layouts/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<div class="px-4 py-2">
<span class="block text-sm text-gray-700">{{ auth()->user()->name }}</span>
<span class="block text-sm text-gray-500">{{ auth()->user()->email }}</span>
<span class="block text-sm text-gray-500">{{ auth()->user()->type }}</span>
</div>
<div class="border-t border-gray-100"></div>
<a href="{{ route('perfil') }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">Perfil</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/dashboard/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<h2 class="text-xl font-bold mb-4">Estatísticas Gerais</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-gray-100 p-4 rounded-lg">
<h3 class="text-lg font-semibold">Tarefas Concluídas</h3>
<h3 class="text-lg font-semibold">Quantidade total de usuários</h3>
<p class="text-3xl font-bold text-green-600">42</p>
</div>
<div class="bg-gray-100 p-4 rounded-lg">
Expand Down
19 changes: 11 additions & 8 deletions resources/views/dashboard/usuarios/editar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@
label="Confirmar Nova Senha"
placeholder="Confirme sua nova senha"
/>

<!-- Campo de Tipo de Usuário -->
<x-partials.select-field
name="type"
label="Tipo de Usuário"
:options="['Admin', 'Empresa', 'Funcionario', 'Convidado']"
value="{{ old('type', $user->type) }}"
required
/>
@if($user->isAdmin())
<x-partials.select-field
name="type"
label="Tipo de Usuário"
:options="['Admin', 'Empresa', 'Funcionario', 'Convidado']"
value="{{ old('type', $user->type) }}"
required
/>
@endif



<!-- Botão de Salvar -->
<div>
Expand Down
5 changes: 4 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
Route::get('/dashboard/usuarios/{id}', [DashboardController::class, 'usuarioById'])
->middleware('can:view-dashboard-usuarios')
->name('dashboard.usuarios.editar');
Route::put('/dashboard/usuarios/{id}', [DashboardController::class, 'updateUsuario'])->name('dashboard.usuarios.update');
Route::put('/dashboard/usuarios/{id}', [DashboardController::class, 'updateUsuario'])
->middleware('can:view-dashboard-usuarios')
->name('dashboard.usuarios.update');



Route::get('/dashboard/perfil', [DashboardController::class, 'perfil'])->name('perfil');
Expand Down

0 comments on commit 27affe5

Please sign in to comment.