#development #laravel #php

When you are using Filament Admin, you might encounter that when you publish your site to production, it doesn't work. The login shows up, but after logging in, you most probably end up with a plain 404 error. Doing the same locally works just fine.

By default, all App\Models\Users can access Filament locally. To allow them to access Filament in production, you must take a few extra steps to ensure that only the correct users have access to the admin panel.

To set up your App\Models\User to access Filament in non-local environments, you must implement the FilamentUser contract:

 1namespace App\Models;
 2
 3use Filament\Models\Contracts\FilamentUser;
 4use Illuminate\Foundation\Auth\User as Authenticatable;
 5
 6class User extends Authenticatable implements FilamentUser
 7{
 8    // ...
 9
10    public function canAccessFilament(): bool
11    {
12        return str_ends_with($this->email, '@yourdomain.com')
13            && $this->hasVerifiedEmail();
14    }
15}

The canAccessFilament() method returns true or false depending on whether the user is allowed to access Filament. In this example, we check if the user's email ends with @yourdomain.com and if they have verified their email address.

This is hidden somewhere in the Filament Documentation ;-).