F
Filamentβ€’12mo ago
Wirkhof

Interface "App\Filament\AvatarProviders\Contracts\AvatarProvider" not found

I have created a file BoringAvatarsProvider.php in app/Filament/AvatarProviders/ and put there this:
<?php

namespace App\Filament\AvatarProviders;

use Filament\Facades\Filament;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;

class BoringAvatarsProvider implements Contracts\AvatarProvider
{
public function get(Model | Authenticatable $record): string
{
$name = str(Filament::getNameForDefaultAvatar($record))
->trim()
->explode(' ')
->map(fn (string $segment): string => filled($segment) ? mb_substr($segment, 0, 1) : '')
->join(' ');

return 'https://source.boringavatars.com/beam/120/' . urlencode($name);
}
}
<?php

namespace App\Filament\AvatarProviders;

use Filament\Facades\Filament;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;

class BoringAvatarsProvider implements Contracts\AvatarProvider
{
public function get(Model | Authenticatable $record): string
{
$name = str(Filament::getNameForDefaultAvatar($record))
->trim()
->explode(' ')
->map(fn (string $segment): string => filled($segment) ? mb_substr($segment, 0, 1) : '')
->join(' ');

return 'https://source.boringavatars.com/beam/120/' . urlencode($name);
}
}
and added this to panel: ->defaultAvatarProvider(BoringAvatarsProvider::class); And I am getting the error message:
Interface "App\Filament\AvatarProviders\Contracts\AvatarProvider" not found
Interface "App\Filament\AvatarProviders\Contracts\AvatarProvider" not found
In the editor the part : implements Contracts\AvatarProvider has Contracts\AvatarProvider with a yellow background and it says on hover: undefined namespace Contracts. Do I need to create some other files to make this work? I have followed the docs here https://filamentphp.com/docs/3.x/panels/users#using-a-different-avatar-provider and there is nothing else to do, no mention about creating additional files, just this one BoringAvatarsProvider.php and putting the ->defaultAvatarProvider(BoringAvatarsProvider::class); in the panel chain.
Solution:
You saw my PR, right? So this is solved?
Jump to solution
3 Replies
Wirkhof
WirkhofOPβ€’12mo ago
OK, apparently there should be an additional import. I just have to figure out what exactly.
Solution
Dennis Koch
Dennis Kochβ€’12mo ago
You saw my PR, right? So this is solved?
Wirkhof
WirkhofOPβ€’12mo ago
Will check on github now. Great the use Filament\AvatarProviders\Contracts; as you added there solved it. Now I see some buiscit or whatnot smiling at me instead of initials πŸ˜‰ . Thanks.
Want results from more Discord servers?
Add your server