google/cloud-storage
Idiomatic PHP client for Google Cloud Storage. Upload, download, and manage buckets/objects, set ACLs, and use the gs:// stream wrapper. Part of the Google Cloud PHP suite with full API docs and authentication guidance.
StorageClient can be instantiated in Laravel’s service container or via facades.storage/app) or third-party packages like spatie/laravel-medialibrary for cloud-native workflows.gs://), enabling transparent file operations (e.g., file_get_contents('gs://bucket/file.txt')), reducing boilerplate in Laravel controllers/services.Filesystem contract via custom adapters (e.g., GoogleCloudStorageAdapter), enabling unified storage handling across local/cloud backends.can:download-file policies).OBJECT_FINALIZE) can trigger Laravel jobs/queues for post-processing (e.g., image optimization, metadata indexing).env() for credential paths and restrict IAM roles.StorageClient instantiation may introduce ~100–300ms latency (HTTP connection to Google APIs). Mitigation: Cache the client instance in Laravel’s cache or use a singleton pattern.php-version constraint in composer.json.Cache-Control: max-age=31536000)?location constraints.README.md or runbooks.spatie/laravel-medialibrary or league/flysystem.RetryOptions).storage/app with Google Cloud Storage for:
gs://).title, alt_text).OBJECT_FINALIZE → HandleVideoTranscodeJob).Phase 1: Pilot with Non-Critical Data
storage/app/public with Cloud Storage for static assets (e.g., gs://bucket/public/assets).$storage = new \Google\Cloud\Storage\StorageClient();
$storage->registerStreamWrapper();
// Now use gs://bucket/path in file_get_contents()
Phase 2: Core Functionality
spatie/laravel-medialibrary) to Cloud Storage.Filesystem contract:
// app/Filesystems/GoogleCloudStorage.php
use Google\Cloud\Storage\StorageClient;
use Illuminate\Contracts\Filesystem\Filesystem;
class GoogleCloudStorage implements Filesystem {
protected $client;
public function __construct(StorageClient $client) { $this->client = $client; }
public function write($path, $contents, $options = []) { /* ... */ }
// Implement other methods (read, delete, etc.)
}
config/filesystems.php:
'disks' => [
'gcs' => [
'driver' => 'google-cloud-storage',
'bucket' => env('GCS_BUCKET'),
'project_id' => env('GCS_PROJECT_ID'),
],
],
Phase 3: Advanced Features
null handling in PHP 7.4).local disk with gcs disk in config.gcs disk for processed images.google/cloud-common.users, posts, etc., tables to store gs://bucket/path instead of storage/app/....Authentication Setup:
roles/storage.admin..env:
GCS_KEY_FILE=/path/to/service-account.json
GCS_BUCKET=my-laravel-app-bucket
GCS_PROJECT_ID=my-gcp-project
Google\Cloud\Storage\StorageClient with:
$storage = new StorageClient([
'keyFilePath' => env('GCS_KEY_FILE'),
'projectId' => env('GCS_PROJECT_ID'),
]);
Core Integration:
Storage::disk('local')->put() with Storage::disk('gcs')->put().// Before: asset('storage/file.jpg')
// After: $file->url() // Returns gs://signed-url
Performance Optimization:
$bucket->upload(
fopen('large-video.mp4', 'r'),
['resumable' => true]
);
$url = $object
How can I help you explore Laravel packages today?