From 156c8c40c404390939fa4b35ab3822385e4d2435 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Thu, 17 Sep 2026 01:03:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D1=84=D0=B8=D0=BB=D1=8C:=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D0=B5=D1=84=D0=BE=D0=BD,=20=D1=81=D0=B0?= =?UTF-8?q?=D0=B9=D1=82,=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=8C,=20=D0=B3=D0=BE=D1=80=D0=BE=D0=B4=20=D0=B8=20?= =?UTF-8?q?=C2=AB=D0=BE=20=D1=81=D0=B5=D0=B1=D0=B5=C2=BB=20=E2=80=94=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BE=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controllers/Web/ProfileController.php | 32 ++++++++------- framework/Models/User.php | 7 +++- ...20260917120000_add_user_profile_fields.php | 39 +++++++++++++++++++ resources/views/admin/user.php | 22 +++++++++++ resources/views/profile.php | 25 ++++++++++++ 5 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 migrations/20260917120000_add_user_profile_fields.php diff --git a/app/Controllers/Web/ProfileController.php b/app/Controllers/Web/ProfileController.php index 9e47720..5ca3993 100644 --- a/app/Controllers/Web/ProfileController.php +++ b/app/Controllers/Web/ProfileController.php @@ -31,26 +31,32 @@ final class ProfileController extends Controller } /** - * Имя и почта. + * Имя, почта и необязательные поля сверх минимума ядра. */ public function update(Request $request, User $user): Response { $data = $this->validate($request, [ - 'name' => 'nullable|max:191', - 'email' => 'nullable|email|max:191|unique:users,email,' . $user->id(), - ], ['name' => 'Имя', 'email' => 'Почта']); + 'name' => 'nullable|max:191', + 'email' => 'nullable|email|max:191|unique:users,email,' . $user->id(), + 'phone' => 'nullable|max:32', + 'website' => 'nullable|url|max:191', + 'position' => 'nullable|max:191', + 'location' => 'nullable|max:191', + 'bio' => 'nullable|max:500', + ], [ + 'name' => 'Имя', 'email' => 'Почта', 'phone' => 'Телефон', + 'website' => 'Сайт', 'position' => 'Должность', 'location' => 'Город', 'bio' => 'О себе', + ]); - $before = ['name' => $user->name, 'email' => $user->email]; + $fields = ['name', 'email', 'phone', 'website', 'position', 'location', 'bio']; + $before = array_intersect_key($user->toArray(), array_flip($fields)); - $user->forceFill([ - 'name' => (string) ($data['name'] ?? ''), - 'email' => (string) ($data['email'] ?? ''), - ])->save(); + $user->forceFill(array_map(static fn (mixed $value): string => (string) ($value ?? ''), $data))->save(); - Audit::updated('user', $user->id(), 'изменён свой профиль', Audit::between($before, [ - 'name' => $user->name, - 'email' => $user->email, - ])); + Audit::updated('user', $user->id(), 'изменён свой профиль', Audit::between( + $before, + array_intersect_key($user->toArray(), array_flip($fields)) + )); $this->flash('Профиль сохранён'); diff --git a/framework/Models/User.php b/framework/Models/User.php index e27b599..0cd301c 100644 --- a/framework/Models/User.php +++ b/framework/Models/User.php @@ -21,7 +21,12 @@ final class User extends Model { protected static string $table = 'users'; - protected array $fillable = ['login', 'email', 'name', 'role_id', 'active']; + protected array $fillable = [ + 'login', 'email', 'name', 'role_id', 'active', + // Профиль сверх минимума ядра: не используются нигде, кроме самой + // карточки — свободны для своих нужд в приложении поверх фреймворка + 'phone', 'website', 'position', 'location', 'bio', + ]; protected array $hidden = ['password_hash']; diff --git a/migrations/20260917120000_add_user_profile_fields.php b/migrations/20260917120000_add_user_profile_fields.php new file mode 100644 index 0000000..64a7c55 --- /dev/null +++ b/migrations/20260917120000_add_user_profile_fields.php @@ -0,0 +1,39 @@ +table('users', function (Blueprint $table): void { + $table->string('phone', 32)->default(''); + $table->string('website', 191)->default(''); + $table->string('position', 191)->default(''); + $table->string('location', 191)->default(''); + $table->string('bio', 500)->default(''); + }); + } + + public function down(): void + { + $this->table('users', function (Blueprint $table): void { + $table->dropColumn('phone'); + $table->dropColumn('website'); + $table->dropColumn('position'); + $table->dropColumn('location'); + $table->dropColumn('bio'); + }); + } +} diff --git a/resources/views/admin/user.php b/resources/views/admin/user.php index 6d6bbb5..944d39e 100644 --- a/resources/views/admin/user.php +++ b/resources/views/admin/user.php @@ -70,6 +70,28 @@ $hint = $isNew ? 'пусто — придумаем сами' : 'пусто +
+

Профиль

+

Необязательные поля — заполняет сам человек в своём профиле.

+ +
+
Телефон
+
phone !== '' ? View::e((string) $user->phone) : '—' ?>
+ +
Сайт
+
website !== '') { ?>website) ?>—
+ +
Должность
+
position !== '' ? View::e((string) $user->position) : '—' ?>
+ +
Город
+
location !== '' ? View::e((string) $user->location) : '—' ?>
+ +
О себе
+
bio !== '' ? nl2br(View::e((string) $user->bio)) : '—' ?>
+
+
+

Устройства

diff --git a/resources/views/profile.php b/resources/views/profile.php index 6634f33..304aaa1 100644 --- a/resources/views/profile.php +++ b/resources/views/profile.php @@ -36,6 +36,31 @@ use Rsgrinko\Proton\View\View; + + + + + + + + + +