Skip to content

Commit

Permalink
Merge pull request #59 from ludndev/dev/ludndev
Browse files Browse the repository at this point in the history
Refactor Configuration for Filament Profile Editing and Avatar Handling
  • Loading branch information
joaopaulolndev authored Dec 5, 2024
2 parents 34bb51a + df19676 commit 990f7d1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
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

0 comments on commit 990f7d1

Please sign in to comment.