customergauge / session
Native PHP Session adapter for Laravel Authentication
Installs: 19 954
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 8
Forks: 2
Open Issues: 0
Requires
- php: >=8.1
- illuminate/auth: >=7.28
- illuminate/contracts: >=7.28
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: >=9.3
README
Laravel PHP Session ⛔
This library provides a NativeSessionUserProvider for Laravel.
Installation
composer require customergauge/session
Usage
Auth configuration
In the auth.php
file, add the following settings:
Default Guard
'defaults' => [ 'guard' => 'php', 'passwords' => 'users', ],
The new Guard configuration
'guards' => [ 'php' => [ 'driver' => \CustomerGauge\Session\NativeSessionGuard::class, 'provider' => \CustomerGauge\Session\NativeSessionUserProvider::class, 'domain' => '.app.mydomain.com', 'storage' => 'tcp://my.redis.address:6379', ], ],
Auth Middleware
Configure the auth
middleware at App\Http\Kernel
with 'auth:php'
UserFactory
The last thing you'll need is to provide your own implementation of UserFactory
and register it in a ServiceProvider.
final class NativeSessionUserFactory implements UserFactory
{
public function make(array $session): ?Authenticatable
{
// $session here is the same as $_SESSION
return new MyUserObject(
$session['id'],
$session['my_user_attribute'],
);
}
}
In the provider:
$this->app->bind(CustomerGauge\Session\Contracts\UserFactory, App\Auth\NativeSessionUserFactory::class);