allow app icon to be used instead of a third party service

This commit is contained in:
notCharles 2025-11-08 15:09:46 -05:00
parent 49f24e37b6
commit a725029e37
4 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace App\AvatarProviders;
use Filament\AvatarProviders\Contracts\AvatarProvider;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
class PelicanAvatarProvider implements AvatarProvider
{
public function get(Model|Authenticatable $record): string
{
$logo = config('app.logo');
if (filled($logo)) {
if (str_starts_with($logo, 'http://') || str_starts_with($logo, 'https://')) {
return $logo;
}
return url($logo);
}
return url('/pelican.svg');
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Extensions\Avatar\Schemas;
use App\Extensions\Avatar\AvatarSchemaInterface;
use App\Models\User;
class AppLogoSchema implements AvatarSchemaInterface
{
public function getId(): string
{
return 'appIcon';
}
public function getName(): string
{
return 'App Icon';
}
public function get(User $user): string
{
$logo = config('app.logo');
if (filled($logo)) {
if (str_starts_with($logo, 'http://') || str_starts_with($logo, 'https://')) {
return $logo;
}
return url($logo);
}
return '/pelican.svg';
}
}

View File

@ -3,6 +3,7 @@
namespace App\Providers\Extensions;
use App\Extensions\Avatar\AvatarService;
use App\Extensions\Avatar\Schemas\AppLogoSchema;
use App\Extensions\Avatar\Schemas\GravatarSchema;
use App\Extensions\Avatar\Schemas\UiAvatarsSchema;
use Illuminate\Support\ServiceProvider;
@ -17,6 +18,7 @@ class AvatarServiceProvider extends ServiceProvider
// Default Avatar providers
$service->register(new GravatarSchema());
$service->register(new UiAvatarsSchema());
$service->register(new AppLogoSchema());
return $service;
});

View File

@ -2,6 +2,7 @@
namespace App\Providers\Filament;
use App\AvatarProviders\PelicanAvatarProvider;
use App\Enums\CustomizationKey;
use App\Filament\Pages\Auth\EditProfile;
use App\Filament\Pages\Auth\Login;
@ -34,6 +35,7 @@ abstract class PanelProvider extends BasePanelProvider
->brandLogo(config('app.logo'))
->brandLogoHeight('2rem')
->favicon(config('app.favicon', '/pelican.ico'))
->defaultAvatarProvider(PelicanAvatarProvider::class)
->topNavigation(function () {
$navigationType = user()?->getCustomization(CustomizationKey::TopNavigation);