ivanvermeyen/laravel-google-drive-demo

How to change folder id?

afrasiyabhaider opened this issue · 2 comments

I want to access multiple folders but folderId is fixed in filesystem.php. How can I change folder id when I want to access another Google Drive Folder?

Hi,

The folder ID is being set in the ServiceProvider.
The underlying GoogleDriveAdapter requires this.
The ID is indeed fetched from the configuration file.

\Storage::extend('google', function($app, $config) {
$client = new \Google_Client();
$client->setClientId($config['clientId']);
$client->setClientSecret($config['clientSecret']);
$client->refreshToken($config['refreshToken']);
$service = new \Google_Service_Drive($client);
$options = [];
if(isset($config['teamDriveId'])) {
$options['teamDriveId'] = $config['teamDriveId'];
}
$adapter = new GoogleDriveAdapter($service, $config['folderId'], $options);
return new \League\Flysystem\Filesystem($adapter);
});

One approach could be to use a root folder ID with some subfolders.

Another way is to tweak the code from the ServiceProvider a bit to accept a folder ID instead of using the one from the config. But I don't think you can use Laravel's extend functionality then. You'll have to create a custom class or function to do so.

I've created a function inside service provider class and then passed a value trough another class ro service provider

--Problem Solved--