From 72a6bfcbe87f7e05956f16147dcffe5ccf8351f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Judica=C3=ABl=20AHYI?= Date: Sun, 1 Dec 2024 12:01:13 +0100 Subject: [PATCH] refactor(): add config for avatar. column name - use of fallback 'avatar_url' to avoid introducing breaking changes in existing installation - update example in `README.md` --- README.md | 5 +++-- config/filament-edit-profile.php | 2 +- database/migrations/add_avatar_url_to_users_table.php.stub | 4 ++-- src/Livewire/EditProfileForm.php | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 79ce952..41f4e31 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ protected $fillable = [ 'name', 'email', 'password', - 'avatar_url', + 'avatar_url', // or column name according to config('filament-edit-profile.avatar_column', 'avatar_url') ]; ``` @@ -162,7 +162,8 @@ class User extends Authenticatable implements HasAvatar // ... public function getFilamentAvatarUrl(): ?string { - return $this->avatar_url ? Storage::url("$this->avatar_url") : null; + $avatarColumn = config('filament-edit-profile.avatar_column', 'avatar_url'); + return $this->$avatarColumn ? Storage::url("$this->$avatarColumn") : null; } } ``` diff --git a/config/filament-edit-profile.php b/config/filament-edit-profile.php index ca5d8ed..6186895 100644 --- a/config/filament-edit-profile.php +++ b/config/filament-edit-profile.php @@ -1,5 +1,5 @@ 'avatar_url', ]; diff --git a/database/migrations/add_avatar_url_to_users_table.php.stub b/database/migrations/add_avatar_url_to_users_table.php.stub index 60c5b48..5627ef3 100644 --- a/database/migrations/add_avatar_url_to_users_table.php.stub +++ b/database/migrations/add_avatar_url_to_users_table.php.stub @@ -12,7 +12,7 @@ return new class extends Migration public function up(): void { Schema::table('users', function (Blueprint $table) { - $table->string('avatar_url')->nullable(); + $table->string(config('filament-edit-profile.avatar_column', 'avatar_url'))->nullable(); }); } @@ -22,7 +22,7 @@ return new class extends Migration public function down(): void { Schema::table('users', function (Blueprint $table) { - $table->dropColumn('avatar_url'); + $table->dropColumn(config('filament-edit-profile.avatar_column', 'avatar_url')); }); } }; diff --git a/src/Livewire/EditProfileForm.php b/src/Livewire/EditProfileForm.php index e8e28cd..6cbb184 100644 --- a/src/Livewire/EditProfileForm.php +++ b/src/Livewire/EditProfileForm.php @@ -28,7 +28,7 @@ public function mount(): void $this->userClass = get_class($this->user); - $this->form->fill($this->user->only('avatar_url', 'name', 'email')); + $this->form->fill($this->user->only(config('filament-edit-profile.avatar_column', 'avatar_url'), 'name', 'email')); } public function form(Form $form): Form @@ -39,7 +39,7 @@ public function form(Form $form): Form ->aside() ->description(__('filament-edit-profile::default.profile_information_description')) ->schema([ - FileUpload::make('avatar_url') + FileUpload::make(config('filament-edit-profile.avatar_column', 'avatar_url')) ->label(__('filament-edit-profile::default.avatar')) ->avatar() ->imageEditor()