F
Filamentβ€’10mo ago
gladjanus43

Password reset for different user model

I have setup a different user model for a separate panel called customer. It all works correct, but I cannot get the passwordReset method to work. This is the new Customer model.
use Filament\Models\Contracts\FilamentUser;
use Filament\Tables\Columns\Layout\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class Customer extends Authenticatable implements FilamentUser
{
use HasApiTokens, HasFactory, Notifiable;

protected $table = 'customers';

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
use Filament\Models\Contracts\FilamentUser;
use Filament\Tables\Columns\Layout\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class Customer extends Authenticatable implements FilamentUser
{
use HasApiTokens, HasFactory, Notifiable;

protected $table = 'customers';

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
9 Replies
gladjanus43
gladjanus43OPβ€’10mo ago
When I try to send the password request it returns the error that the email is not found. It still looks in the User table for some reason. Do I need to specifiy somewhere in the->passwordReset which model it needs to look for?
gladjanus43
gladjanus43OPβ€’10mo ago
Medium
Change Laravel Authentication Model for FilamentPHP 3
I was developing an e-commerce platform where I wanted to separate the customers from the website administrators for various reasons.
gladjanus43
gladjanus43OPβ€’10mo ago
Also setup the ->authGuard('customer'); inside the PackagePanelProvider class
Abel Cobreros
Abel Cobrerosβ€’10mo ago
Probably you need to override in the model the sendPasswordResetNotification method from the CanResetPassword contract By default laravel does this
Abel Cobreros
Abel Cobrerosβ€’10mo ago
No description
Abel Cobreros
Abel Cobrerosβ€’10mo ago
I think you have to create your own ResetPasswordNotificaton version
gladjanus43
gladjanus43OPβ€’10mo ago
Allright, I will google some information on this... The laravel docs say I need to implement the CanResetPasswordContract on the model
Abel Cobreros
Abel Cobrerosβ€’10mo ago
It might be the case yeah I just remembered doing something like that for a non-filament project a while ago but the solution should be related to that contract
gladjanus43
gladjanus43OPβ€’10mo ago
Jeah, the docs make it look easy πŸ˜› But not really sure how it translates to filament
Want results from more Discord servers?
Add your server