After I installed the Laravel Filament on my local env and very impress because It’s to easy to setup, nice UI and document.
And
then I push it on production server. The 403 page show 😄
I have no idea about it and search google. So, we miss one step which is not mention in the v2 document.
So, We need implements Filament\Models\Contracts\FilamentUser
in the app/Models/User.php
model and add method canAccessFilament
.
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Filament\Models\Contracts\FilamentUser;
class User extends Authenticatable implements FilamentUser
{
use HasApiTokens, HasFactory, Notifiable;
/**
* 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',
];
public function canAccessFilament(): bool
{
return str_ends_with($this->email, '@xxx.com');
}
}
Top comments (5)
Thanks!!
With Filament 3 this is the needed function:
Don't forget to add this to the top:
Thank you! I had missed seeing that in the documentation. I wasted several days and headaches trying to solve it.
Thank you very much, it saved me after several hours of errors.
Just create account to share some love. Ty a lot. Wasted 3 hours.
Thank you a ton! for me saved hours of time