avatar
save file with Google drive Laravel

Install package for Google Drive API V3

composer require nao-pon/flysystem-google-drive:~1.1

If not Google Drive API version V3, let's go re-use Google Drive API V2.

composer require nao-pon/flysystem-google-drive:~1.0.0

Next step, we need to add App\Providers\GoogleDriveServiceProvider::class, which locates in config/app.php.

App\Providers\GoogleDriveServiceProvider::class,

Conduct of configuration is not always easy, and the manipulation need to add some information below.

+ Google Client ID and Secret

+ Refresh Token

+ Folder ID

'google' => [
    'driver' => 'google',
    'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
    'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
    'accessToken' => env('GOOGLE_DRIVE_ACCESS_TOKEN'),
    'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'),
],

If there is a error in registering GoogleDriveServiceProvider::class that you lack of it and can copy two files, one that GoogleDriveServiceProvider.php and one that GoogleDriveAdapter.php in Laravel project.

And, finally, would can declare instance like this.

use \Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Route;
/.../
Route::get('test/google-drive-v3', function ($params) {
    Storage::disk('google')->put('favicon.ico',  public_path('favicon.ico'));
});
24
create Laravel project with composer and specific version
You need to login to do this manipulation!