Hey everyone,
I’m having trouble getting Google Drive to work with my Laravel 11 project. I’ve been using the masbug/flysystem-google-drive-ext package (version 2.3.0) but it’s not playing nice after upgrading from Laravel 6.
Here’s a simplified version of what I’m trying to do:
use CloudStorage\DriveAdapter;
use CloudStorage\DriveService;
class CloudController extends BaseController
{
private $driveClient;
private $driveAdapter;
private $driveService;
public function __construct()
{
$this->driveClient = new DriveClient();
$this->driveClient->setAuth('client_id', 'client_secret', 'refresh_token');
$this->driveAdapter = new DriveAdapter($this->driveClient);
$this->driveService = new DriveService($this->driveAdapter);
}
public function uploadFile($fileName, $fileContent)
{
return $this->driveService->putFile('my_folder/' . $fileName, $fileContent);
}
}
The code worked fine in Laravel 6, but now it’s throwing errors. Any ideas on how to fix this or alternative approaches for Google Drive integration in Laravel 11? Thanks in advance!
I’ve been down this road before, and it can be frustrating. The masbug/flysystem-google-drive-ext package is great, but it’s not officially updated for Laravel 11 yet. Here’s what worked for me:
I ended up using the league/flysystem-google-cloud-storage package instead. It’s more actively maintained and plays nicely with Laravel 11’s filesystem changes.
First, install it via composer:
composer require league/flysystem-google-cloud-storage
Then, update your config/filesystems.php to include a new disk:
'gcs' => [
'driver' => 'gcs',
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'),
'key_file' => env('GOOGLE_CLOUD_KEY_FILE'),
'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET'),
],
Now you can use it like any other Laravel filesystem disk:
Storage::disk('gcs')->put('file.txt', 'Contents');
This approach has been more reliable for me in Laravel 11. Hope it helps!
hey markseeker, i feel ur pain. had similar issues upgrading to L11. have u tried the spatie/laravel-google-cloud-storage package? its pretty solid for google drive integration. just install it, set up ur credentials in .env, and use Storage::disk(‘google’) to interact. might save u some headaches!
I encountered a similar challenge after upgrading to Laravel 11. The changes in Laravel’s filesystem handling and third-party integrations can cause legacy packages to fail. In my case, I switched to using the google/apiclient package directly instead of relying on the older flysystem extension. I set up my Google Console credentials, configured a custom filesystem driver in config/filesystems.php, and used Laravel’s Storage facade for interactions. Although it requires a bit more setup, this approach has proven to be more robust and compatible with Laravel 11.