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.
- PHP 8.2 or higher
- Laravel 10.0 or higher
- PHP Extension:
grpc
- PHP Extension:
protobuf
- Google Cloud Firestore Credentials
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'),
],
];
Please see the Authentication guide for more information on authenticating your Google Cloud Firestore client.
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
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',
],
],
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
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
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.