egs33 / laravel-datastore-auth
1.4.0
2020-09-16 13:00 UTC
Requires
- php: ^7.1
- google/cloud-datastore: ^1.5
- laravel/framework: ^5.5.0 || ^6.0.0 || ^7.0.0 || ^8.0.0
Requires (Dev)
- google/cloud-datastore: ^1.5.6
- guzzlehttp/guzzle: >=6.3.0
- mockery/mockery: ^1.1
- orchestra/testbench: >=3.5
- phpunit/phpunit: ^6.0 || ^7.0 || ^8.0
README
使用 Laravel 认证 以及 Google Datastore
需求
- Laravel >= 5.5.0
- Composer
安装
$ composer require egs33/laravel-datastore-auth
$ php artisan vendor:publish --provider="DatastoreAuth\DatastoreAuthServiceProvider"
快速开始
将认证驱动设置为 datastore。例如,在 config/auth.php
'providers' => [ 'users' => [ 'driver' => 'datastore' ] ],
然后就可以像 Laravel 认证 一样使用了
用法
创建用户
$userConfig = [ 'name' => 'hoge', 'email' => 'hoge@example.com', 'password' => 'secret' ]; $userProvider = Auth::createUserProvider('users'); $userProvider->create($userConfig); // or DatastoreAuth::create($userConfig);
获取当前用户等。
使用 Auth 门面。与 Laravel 认证 相同
$user = Auth::user(); // get current user $isLoggedIn = Auth::check();
更新用户数据
$user['name'] = 'new-name'; $user['group'] = 'new-group'; $user->save();
配置
配置文件为 config/datastore_auth.php
默认为
[
'client_config' => [],
'kind' => 'users',
'cache' => [
'isEnabled' => false,
'keyPrefix' => \DatastoreAuth\DatastoreUserProvider::class . ':',
'ttl' => null,
]
]
client_config 被传递给 Google\Cloud\Datastore\DatastoreClient 的构造函数。请参阅 google/cloud-datastore 的文档。
kind 是用户表的类型名称。
缓存
缓存仅在通过 ID 获取用户时使用。缓存存储由您 Laravel 项目的 config/cache.php 中指定。ttl 以秒为单位表示,不受 Laravel 版本的影响。如果为 null,则无过期。
当调用 DatastoreUserProvider#resetPassword、DatastoreUserProvider#save、DatastoreUserProvider#updateRememberToken 或 User#save 时,缓存将被清除。但在必要时,您可以调用 DatastoreUserProvider#deleteCache。