Skip to content

Commit aca3fe0

Browse files
committed
feat: implement admin user editing functionality
1 parent 5c51e2e commit aca3fe0

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

app/Http/Controllers/Admin/UserController.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,25 @@ public function index(Request $request): View
2323

2424
return view('admin.users', compact('users'));
2525
}
26+
27+
public function edit(User $user)
28+
{
29+
return view('admin.users.edit', compact('user'));
30+
}
31+
32+
public function update(Request $request, User $user)
33+
{
34+
$data = $request->validate([
35+
'name' => 'required|string|max:255',
36+
'github_name' => 'nullable|string|max:255',
37+
'is_admin' => 'sometimes|boolean',
38+
]);
39+
40+
$data['is_admin'] = $request->has('is_admin');
41+
42+
$user->update($data);
43+
44+
return redirect()->route('admin.users.index')
45+
->with('success', 'User updated');
46+
}
2647
}

resources/views/admin/users.blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<th>{{ __('admin.users.table.email') }}</th>
3030
<th>{{ __('admin.users.table.role') }}</th>
3131
<th>{{ __('admin.users.table.created') }}</th>
32+
<th>{{ __('admin.users.table.actions') }}</th>
3233
</tr>
3334
</thead>
3435
<tbody>
@@ -63,6 +64,13 @@
6364
{{ $user->created_at->format('d.m.Y H:i') }}
6465
</small>
6566
</td>
67+
<td>
68+
<a href="{{ route('admin.users.edit', $user) }}"
69+
class="btn btn-sm btn-outline-primary"
70+
title="{{ __('admin.users.edit') }}">
71+
<i class="bi bi-pencil"></i>
72+
</a>
73+
</td>
6674
</tr>
6775
@empty
6876
<tr>

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
Route::resource('pages', 'PagesController')->only('show');
5454

5555
Route::namespace('Admin')->prefix('admin')->name('admin.')->group(function (): void {
56-
Route::resource('users', 'UserController')->only('index');
56+
Route::resource('users', 'UserController')->only('index', 'edit', 'update');
5757
Route::resource('comments', 'CommentController')->only('index');
5858
Route::resource('solutions', 'SolutionController')->only('index');
5959
});

0 commit comments

Comments
 (0)