Issues with Google Drive filesystem package compatibility in Laravel 11 upgrade

I’m having trouble with Google Drive integration after upgrading my Laravel project. The masbug/flysystem-google-drive-ext package that worked fine in older Laravel versions seems to have compatibility issues now.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Controller;
use Illuminate\Support\Facades\Storage;
use Masbug\Flysystem\GoogleDrive\GoogleDriveAdapter;
use Masbug\Flysystem\GoogleDrive\GoogleDriveServiceProvider;

class DriveManagerController extends Controller
{
    private $googleClient;
    private $targetFolderId;
    private $driveService;
    private $filesystemAdapter;
    private $provider;
    private $appClientId = '###';
    private $appClientSecret = '###';
    private $userRefreshToken = '###';

    public function __construct()
    {
        $this->googleClient = new \Google_Client();
        $this->googleClient->setClientId($this->appClientId);
        $this->googleClient->setClientSecret($this->appClientSecret);
        $this->googleClient->refreshToken($this->userRefreshToken);
        $this->driveService = new \Google_Service_Drive($this->googleClient);
        $this->targetFolderId = '1AbC2dEf3GhI4jKl5MnO6pQr7StU8vWx9';

        $this->filesystemAdapter = new GoogleDriveAdapter([
            'clientId' => $this->appClientId,
            'clientSecret' => $this->appClientSecret,
            'refreshToken' => $this->userRefreshToken,
            'service' => $this->driveService,
        ]);

        $this->provider = new GoogleDriveServiceProvider($this->filesystemAdapter);
    }

    public function makeNewFolder($dirName, $parentId)
    {
        $metadata = [
            'name' => $dirName,
            'parents' => [$parentId],
            'mimeType' => 'application/vnd.google-apps.folder',
        ];

        $newFolder = $this->provider->createDirectory($dirName, $parentId);
        return $newFolder['id'];
    }

    public function folderExists($dirName, $parentId)
    {
        $contents = $this->provider->listContents('/', true);

        foreach ($contents as $item) {
            if ($item['type'] == 'dir' && $item['basename'] == $dirName) {
                return true;
            }
        }
        return false;
    }

    public function storeFile($folderId, $fileContent, $fileName)
    {
        $uploadResult = $this->provider->write($folderId+'/'+$fileName, $fileContent);
        return $uploadResult;
    }
}

The code worked perfectly when I was using Laravel 6, but after upgrading to Laravel 10 and now trying Laravel 11, it’s not functioning properly. Can anyone suggest a better approach or alternative package for Google Drive integration that’s compatible with newer Laravel versions?

That’s happening because masbug is basically dead - hasn’t been updated for newer Laravel versions. I hit the same wall upgrading from Laravel 9 to 11 and ditched it for Google’s official API client plus Laravel’s filesystem stuff. Skip the third-party Flysystem adapters and just use the google/apiclient package with a custom storage driver. You’ll have way more control and won’t be stuck with dead packages. Build a custom filesystem driver that works with Laravel’s filesystem contract but uses Google’s official SDK under the hood. Yeah, you’ll need to refactor some code, but it’s worth it - you’re using Google’s maintained libraries instead of community packages that go stale.

You’ve got dependency conflicts because Laravel 11 bumped Flysystem to v3, but masbug was built for older versions. Hit the same issue upgrading from Laravel 8 to 11 last month. Don’t waste time fighting outdated packages - switch to nao-pon/flysystem-google-drive instead. It’s updated for Flysystem v3. Config’s a bit different but migration’s easy. Your constructor’s way too complex anyway. Laravel 11’s filesystem config in config/filesystems.php handles most of this once you register the driver right. Also, your storeFile method uses plus signs for string concatenation - that should be dots in PHP. Might be causing extra problems on top of the package issue.

Had the same issue! Switch to spatie/flysystem-google-drive - it’s way better maintained and works perfectly with Laravel 11. The masbug package hasn’t been updated in forever, that’s why you’re getting compatibility issues.