Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Configuration for Filament Profile Editing and Avatar Handling #59

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ If needed you can define the disk and visibility of the avatar image. In the con

```php
return [
'disk' => 's3',
'visibility' => 'public',
'disk' => env('FILESYSTEM_DISK', 'public'),
'visibility' => 'public', // or replace by filesystem disk visibility with fallback value
];
```

Expand All @@ -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')
];
```

Expand All @@ -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;
}
}
```
Expand Down
4 changes: 3 additions & 1 deletion config/filament-edit-profile.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

return [

'avatar_column' => 'avatar_url',
'disk' => env('FILESYSTEM_DISK', 'public'),
'visibility' => 'public', // or replace by filesystem disk visibility with fallback value
];
4 changes: 2 additions & 2 deletions database/migrations/add_avatar_url_to_users_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand All @@ -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'));
});
}
};
4 changes: 2 additions & 2 deletions src/Livewire/EditProfileForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
Loading