Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cgauge/laravel-php-session
https://github.com/cgauge/laravel-php-session
hacktoberfest laravel php session
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/cgauge/laravel-php-session
- Owner: cgauge
- License: mit
- Created: 2020-10-03T19:07:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-12T11:31:07.000Z (7 months ago)
- Last Synced: 2024-10-13T02:07:16.757Z (3 months ago)
- Topics: hacktoberfest, laravel, php, session
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 9
- Watchers: 8
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Code Coverage](https://scrutinizer-ci.com/g/cgauge/laravel-php-session/badges/coverage.png?b=main)](https://scrutinizer-ci.com/g/cgauge/laravel-php-session/?branch=main)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/cgauge/laravel-php-session/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/cgauge/laravel-php-session/?branch=main)# Laravel PHP Session ⛔
This library provides a NativeSessionUserProvider for Laravel.
# Installation
```bash
composer require customergauge/session
```# Usage
### Auth configuration
In the `auth.php` file, add the following settings:
Default Guard
```php
'defaults' => [
'guard' => 'php',
'passwords' => 'users',
],
```The new Guard configuration
```php
'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);
```