Skip to content

Commit 43964c9

Browse files
authored
Merge pull request #1863 from GreedVal/fix-issue#1794
Fix issue#1794
2 parents 05e8b11 + 50bb326 commit 43964c9

File tree

14 files changed

+200
-6
lines changed

14 files changed

+200
-6
lines changed

app/DTO/Admin/UpdateUserData.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\DTO\Admin;
4+
5+
use Spatie\LaravelData\Attributes\Validation\Nullable;
6+
use Spatie\LaravelData\Attributes\Validation\Required;
7+
use Spatie\LaravelData\Attributes\Validation\Max;
8+
use Spatie\LaravelData\Data;
9+
10+
class UpdateUserData extends Data
11+
{
12+
public function __construct(
13+
#[Required]
14+
#[Max(255)]
15+
public string $name,
16+
#[Nullable]
17+
#[Max(255)]
18+
public ?string $github_name,
19+
#[Nullable]
20+
public ?bool $is_admin,
21+
) {
22+
}
23+
}

app/Http/Controllers/Admin/UserController.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers\Admin;
44

5+
use App\DTO\Admin\UpdateUserData;
56
use App\Models\User;
67
use Illuminate\Http\Request;
78
use Illuminate\View\View;
@@ -23,4 +24,21 @@ public function index(Request $request): View
2324

2425
return view('admin.users', compact('users'));
2526
}
27+
28+
public function edit(User $user)
29+
{
30+
return view('admin.users.edit', compact('user'));
31+
}
32+
33+
public function update(UpdateUserData $request, User $user)
34+
{
35+
$user->update([
36+
'name' => $request->name,
37+
'github_name' => $request->github_name,
38+
'is_admin' => $request->is_admin,
39+
]);
40+
41+
return redirect()->route('admin.users.index')
42+
->with('success', 'User updated');
43+
}
2644
}

app/Models/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @property string $name
2323
* @property string $email
2424
* @property string $github_name
25-
* @property bool $is_admin
25+
* @property bool $admin
2626
* @property \Illuminate\Support\Carbon|null $email_verified_at
2727
* @property string $password
2828
* @property string|null $remember_token
@@ -58,7 +58,7 @@ class User extends Authenticatable implements MustVerifyEmail
5858
* @var string[]
5959
*/
6060
protected $fillable = [
61-
'name', 'email', 'password',
61+
'name', 'email', 'password', 'github_name', 'is_admin',
6262
];
6363

6464
/**

app/Policies/UserPolicy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public function update(?User $user, User $resourceUser): bool
1313
{
1414
return $resourceUser->is($user);
1515
}
16+
17+
public function accessAdmin(User $user): bool
18+
{
19+
return $user->is_admin;
20+
}
1621
}

database/seeders/UsersTableSeeder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Database\Seeders;
44

5-
use App\Models\Chapter;
65
use App\Models\User;
76
use Illuminate\Database\Seeder;
87

resources/lang/en/account.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
'current_email' => 'Current email',
1414
'go_to_gravatar' => 'Go to Gravatar.com',
1515
'github_name' => 'GitHub username',
16+
'admin' => 'Admin',
17+
'name' => 'Name',
1618
];

resources/lang/en/admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
],
3636
'empty' => 'No users found',
3737
'not_available' => 'N/A',
38+
'edit' => 'Edit User',
3839
],
3940
'comments' => [
4041
'title' => 'Comments',

resources/lang/ru/account.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
'current_email' => 'Текущий email',
1414
'go_to_gravatar' => 'Перейти на Gravatar.com',
1515
'github_name' => 'Имя на GitHub',
16+
'admin' => 'Админ',
17+
'name' => 'Имя',
1618
];

resources/lang/ru/admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'email_not_verified' => 'Email не подтвержден',
3535
],
3636
'empty' => 'Пользователи не найдены',
37+
'edit' => 'Редактирование пользователя',
3738
],
3839
'comments' => [
3940
'title' => 'Комментарии',

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>

0 commit comments

Comments
 (0)