F
Filament14mo ago
Askancy

error after HasName statement

I need to indicate a different hasname, I followed the guide and in my User.php model I have:
<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
[...]
use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasName;


class User extends Authenticatable implements FilamentUser, HasName
[...]

public function getFilamentName(): string
{
return "{$this->name} {$this->last_name}";
}
<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
[...]
use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasName;


class User extends Authenticatable implements FilamentUser, HasName
[...]

public function getFilamentName(): string
{
return "{$this->name} {$this->last_name}";
}
But I get the error: Class App\Models\User contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Filament\Models\Contracts\FilamentUser::canAccessPanel) I get the error even if I only put FilamentUser, if I use HasName alone, I don't get the error
class User extends Authenticatable implements FilamentUser
class User extends Authenticatable implements FilamentUser
Solution:
The error message is telling you what PHP requires: If you're going to implement the FilamentUser contract, then you must fully implement all the methods that that contract requires. The error message also tells you exactly what method you haven't implemented on your User class yet (ie: the canAccessPanel() method). You can see more about canAccessPanel in the Filament docs.
Jump to solution
1 Reply
Solution
DrByte
DrByte14mo ago
The error message is telling you what PHP requires: If you're going to implement the FilamentUser contract, then you must fully implement all the methods that that contract requires. The error message also tells you exactly what method you haven't implemented on your User class yet (ie: the canAccessPanel() method). You can see more about canAccessPanel in the Filament docs.
Want results from more Discord servers?
Add your server