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 ? 'пусто — придумаем сами' : 'пусто +
Необязательные поля — заполняет сам человек в своём профиле.
+ +