richan-fongdasen / firestore-laravel
A Google Cloud Firestore driver for Laravel Cache and Session.
Fund package maintenance!
richan-fongdasen
Requires
- php: ^8.2
- ext-grpc: *
- ext-protobuf: *
- google/cloud-firestore: ^1.43.1
- illuminate/cache: ^10.0||^11.0
- illuminate/contracts: ^10.0||^11.0
- illuminate/session: ^10.0||^11.0
- illuminate/support: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
README
This package allows you to use Google Cloud Firestore as a driver for Cache and Session store in Laravel application. This package is built on top of the official Google Cloud Firestore PHP client library.
Warning
This package is not yet compatible with Laravel Octane.
Requirements
- PHP 8.2 or higher
- Laravel 10.0 or higher
- PHP Extension:
grpc
- PHP Extension:
protobuf
- Google Cloud Firestore Credentials
Installation
You can install the package via composer:
composer require richan-fongdasen/firestore-laravel
You can publish the config file with:
php artisan vendor:publish --tag="firestore-laravel-config"
This is the contents of the published config file:
return [ 'project_id' => env('GOOGLE_CLOUD_PROJECT'), 'credentials' => env('GOOGLE_APPLICATION_CREDENTIALS'), 'database' => env('FIRESTORE_DATABASE', '(default)'), 'cache' => [ 'collection' => env('FIRESTORE_CACHE_COLLECTION', 'cache'), 'key_attribute' => env('FIRESTORE_CACHE_KEY_ATTR', 'key'), 'value_attribute' => env('FIRESTORE_CACHE_VALUE_ATTR', 'value'), 'expiration_attribute' => env('FIRESTORE_CACHE_EXPIRATION_ATTR', 'expired_at'), ], 'session' => [ 'collection' => env('FIRESTORE_SESSION_COLLECTION', 'sessions'), ], ];
Configuration
Setting Up Firestore Authentication
Please see the Authentication guide for more information on authenticating your Google Cloud Firestore client.
Package Configuration
You can configure the package by setting the following environment variables in your .env
file.
GOOGLE_CLOUD_PROJECT=your-google-cloud-project-id GOOGLE_APPLICATION_CREDENTIALS="/path-to/your-service-account.json" FIRESTORE_DATABASE="(default)" FIRESTORE_CACHE_COLLECTION=cache FIRESTORE_CACHE_KEY_ATTR=key FIRESTORE_CACHE_VALUE_ATTR=value FIRESTORE_CACHE_EXPIRATION_ATTR=expired_at FIRESTORE_SESSION_COLLECTION=sessions
Cache Store Configuration
In order to use Firestore as a cache store, you need to append the following configuration into the config/cache.php
file.
'stores' => [ 'firestore' => [ 'driver' => 'firestore', ], ],
Session Driver Configuration
In order to use Firestore as a session store, you need to modify the SESSION_DRIVER
environment variable in your .env
file.
SESSION_DRIVER=firestore
Usage
There is no special usage for this package. You can use the Cache and Session store as you normally do in Laravel.
// Cache store Cache::put('key', 'value', 60); // Store a value in the cache for 60 seconds $value = Cache::get('key'); // Retrieve a value from the cache // Session session(['key' => 'value']); // Store a value in the session $value = session('key'); // Retrieve a value from the session
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.