AppServiceProvider
use App\Overrides\Auth\EloquentUserProvider; <-- class extends \Illuminate\Auth\EloquentUserProvider
use App\Overrides\Auth\UserProvider; // <-- contract extends \Illuminate\Contracts\Auth\UserProvider
register()
{
// some DI
$this->overrideSession();
}
private function overrideSession(): void
{
$this->app->singleton(
UserProvider::class,
static fn(Application $app) => new EloquentUserProvider(
hasher: $app->make('hash'),
model: config('auth.providers.users.model')
)
);
$this->app['auth']->extend(
'filament-session',
static function (Application $app) {
$guard = new SessionGuard(
name: 'filament-session',
provider: $app->make(UserProvider::class),
session: $app->make('session.store'),
request: $app->make('request')
);
if (method_exists($guard, 'setCookieJar')) {
$guard->setCookieJar($app->make('cookie'));
}
if (method_exists($guard, 'setDispatcher')) {
$guard->setDispatcher($app->make('events'));
}
if (method_exists($guard, 'setRequest')) {
$guard->setRequest($app->refresh('request', $guard, 'setRequest'));
}
return $guard;
}
);
}