- How do I configure Google Cloud Storage as a Laravel filesystem disk?
- Add the disk to `config/filesystems.php` under the `disks` array with the `google` driver. Specify your bucket name, project ID, and service account key file path. Example: `'driver' => 'google', 'bucket' => env('GCS_BUCKET'), 'key_file' => storage_path('app/gcs-key.json')`. Ensure the key file has proper permissions.
- Does this package support Laravel’s Storage facade (e.g., Storage::put())?
- Yes, once configured as a disk, you can use Laravel’s Storage facade methods like `Storage::disk('gcs')->put()` just like any other filesystem. The adapter bridges Flysystem’s abstraction with Laravel’s filesystem interface seamlessly.
- What Laravel versions and PHP versions are supported?
- This package works with Laravel 8+ and requires PHP 7.4+. It relies on Flysystem v3+, which is compatible with these Laravel versions. For older Laravel versions, you may need an older Flysystem adapter version.
- Can I use this for large file uploads or streaming?
- Yes, the adapter supports streaming uploads and downloads, which is ideal for large files or performance-sensitive applications. This avoids memory issues by processing files in chunks rather than loading them entirely into memory.
- How do I handle authentication for Google Cloud Storage in Laravel?
- Authentication is typically handled via a service account JSON key file. Store the path to this file in your `.env` (e.g., `GCS_KEY_FILE=path/to/key.json`) and reference it in your filesystem configuration. For CI/CD, consider using temporary credentials via `Google_Auth_AssertionCredentials`.
- Are there any known limitations or edge cases with this adapter?
- The adapter lacks some GCS-specific features like lifecycle policies or CORS configuration, which must be managed directly via the Google Cloud Console. Additionally, error handling for GCS-specific issues (e.g., quota limits) may require custom logic in your Laravel application.
- Can I use this alongside other Laravel storage adapters (e.g., S3)?
- Yes, you can configure multiple disks in `config/filesystems.php`, including both Google Cloud Storage and S3. This allows you to route files to different backends based on your application’s needs, such as using GCS for media assets and S3 for backups.
- How do I monitor performance or costs for Google Cloud Storage in Laravel?
- Google Cloud provides built-in monitoring tools like Cloud Monitoring and Logging. For Laravel, you can log storage operations (e.g., uploads/downloads) using Laravel’s logging system or integrate with Google’s API for detailed metrics. Consider setting up alerts for cost thresholds or unusual activity.
- What’s the best way to handle failures or downtime with Google Cloud Storage?
- Implement a fallback strategy, such as caching frequently accessed files locally or using a multi-cloud approach. For transient failures, consider using a circuit breaker like `spatie/flysystem-circuit-breaker` to prevent cascading errors in your Laravel application.
- Are there alternatives to this package for Laravel and Google Cloud Storage?
- Yes, you could use the official Google Cloud PHP client library (`google/cloud-storage`) directly or explore other Flysystem adapters like `league/flysystem-aws-s3` for S3 compatibility. However, this package provides a Laravel-native integration with GCS, simplifying configuration and usage.