google/cloud-storage
Idiomatic PHP client for Google Cloud Storage. Upload/download objects, manage buckets and permissions (ACLs), use a gs:// stream wrapper, and integrate with Google Cloud PHP authentication. Great for backups, archival, and serving large files.
Strong Fit for Laravel/PHP Ecosystems: The package is idiomatic PHP and integrates seamlessly with Laravel’s Composer-based dependency management. Its PSR-compliant design aligns with Laravel’s service container and facade patterns, enabling clean integration via service providers or bindings.
gs://) replaces storage:disk for GCS, enabling unified file I/O (e.g., Storage::put('gs://bucket/file')).publicRead) map to Laravel’s authorization layers (e.g., Gates, Policies).HandleGCSUpload::dispatch()).Microservices & Monolith Compatibility:
StorageClient in Laravel’s app container for shared access.GCSProxy) to abstract storage logic.Laravel-Specific Levers:
$this->app->singleton(StorageClient::class, fn() => new StorageClient([
'keyFile' => storage_path('service-account.json'),
'projectId' => config('services.gcs.project_id'),
]));
// app/Facades/GCS.php
public static function upload(string $path, string $bucket, array $options = []): void {
resolve(StorageClient::class)->bucket($bucket)->upload(fopen($path, 'r'), $options);
}
Filesystem to delegate to GCS (e.g., GcsAdapter for Storage::disk('gcs')).Authentication:
keyFile in config/services.php).keyFile/keyFilePath are deprecated; migrate to credentials.json or environment variables.| Risk Area | Severity | Mitigation |
|---|---|---|
| Authentication Complexity | Medium | Use Laravel’s config/cache to store credentials; rotate keys via Vault or Secret Manager. |
| Stream Handling | Low | Test with large files (>1GB); monitor memory usage (streams are non-blocking). |
| Soft-Delete/Restore | Medium | Validate restore tokens in Laravel’s authorization middleware. |
| HNS (Hierarchical Namespace) | Low | Enable only if using multi-region buckets; otherwise, stick to flat namespace. |
| Retry Logic | Low | Configure exponential backoff via StorageClient constructor. |
| PHP 8.4+ Compatibility | Low | Package supports PHP 8.4; test with Laravel’s strict typing. |
Storage Strategy:
local, s3), or is it supplemental (e.g., for media)?Performance SLAs:
Compliance:
Cost Optimization:
Disaster Recovery:
Team Skills:
Laravel Core:
StorageClient as a singleton or contextual binding.Illuminate\Filesystem\FilesystemAdapter with a GCS-specific adapter.HandleGCSUpload::dispatch()).Infrastructure:
Extensions:
GcsAdapter.| Phase | Action | Tools/Libraries |
|---|---|---|
| Assessment | Audit current storage usage (e.g., S3, local) and map to GCS equivalents. | aws s3 ls → gsutil ls; Laravel Storage facade. |
| Pilot | Migrate non-critical assets (e.g., thumbnails) to GCS. | Storage::disk('gcs')->put(). |
| Hybrid | Use GCS for uploads, keep legacy for reads (dual-write). | Laravel FilesystemManager aliases. |
| Cutover | Replace all Storage::disk() calls with GCS; validate ACLs and lifecycle rules. |
php artisan storage:link gcs. |
| Optimize | Enable CDN, lifecycle policies, and monitoring. | Cloud CDN; GCS Lifecycle Rules. |
Laravel Versions:
strict_types=1).GCS Features:
Conflict Risks:
public/storage symlinks (use gs:// explicitly).chmod won’t work; use GCS predefined ACLs (e.g., publicRead).Authentication Setup:
roles/storage.objectAdmin).credentials.json in Laravel’s .env or Vault.Core Integration:
config/gcs.php) for bucket names, retries, and defaults.StorageClient in a service provider.Facade/Adapter Layer:
GCS facade or extend FilesystemAdapter for Storage::disk('gcs').Testing:
StorageClient (use Google\Cloud\Storage\Mock\StorageClient).phpunit.xml env vars).Performance Tuning:
Google\Cloud\Storage\Batch).Monitoring:
How can I help you explore Laravel packages today?