If you're utilizing the Breezy plugin, all user avatars are uploaded to the /storage/app/public
directory. If you prefer to keep your avatars organized in a sub-folder, just follow these steps.
Step 1: Create a new storage disk
Begin by adding a new storage disk configuration in your /config/filesystems.php
.
'disks' => [
...
...
'avatars' => [
'driver' => 'local',
'root' => storage_path('app/public/avatars'),
'url' => env('APP_URL').'/storage/avatars',
'visibility' => 'public',
'throw' => false,
],
],
Step 2: Extend the BreezyCore class
To set the storage disk, we need to override a method. Create a new class that extends \Jeffgreco13\FilamentBreezy\BreezyCore
and place it somewhere in your /app
directory. In my case, I placed it in the /app/Filament/Plugins
folder.
<?php
namespace App\Filament\Plugins;
use Filament\Forms;
class BreezyCore extends \Jeffgreco13\FilamentBreezy\BreezyCore
{
public function getAvatarUploadComponent()
{
$fileUpload = Forms\Components\FileUpload::make('avatar_url')
->disk('avatars')
->label(__('filament-breezy::default.fields.avatar'))
->avatar();
return is_null($this->avatarUploadComponent) ? $fileUpload : $this->evaluate($this->avatarUploadComponent, namedInjections: [
'fileUpload' => $fileUpload,
]);
}
}
Step 3: Set storage disk in your User model
Update the getFilamentAvatarUrl()
function found in your /app/Models/User
file and configure the storage disk accordingly.
public function getFilamentAvatarUrl(): ?string
{
return $this->avatar_url ? Storage::disk('avatars')
->url($this->avatar_url) : null;
}
Step 4: Register the plugin in your Filament service provider.
Update the plugin class that you previously registered in your Filament service provider to use the new class.
->plugins([
\App\Filament\Plugins\BreezyCore::make()
]);
Now your avatars should be more organized than before.
Top comments (0)