public function googleDriveFolder() { $googleDriveObject = GoogleDrive::findOrNew(Auth::id()); $access_token = $googleDriveObject->access_token; }
} if ($googleDriveId == 1) { $userConfig[1] = 1; } else { $userConfig[1] = 0; } return view('pages.settings')->with('userConfig', $userConfig); }); Route::get('/home', function () { if (Auth::guest()) { return view('auth.login'); } $userConfig = array(); $dropboxId = Dropbox::where('userId', Auth::id())->count(); //var_dump($dropboxId); $googleDriveId = GoogleDrive::where('userId', Auth::id())->count(); if ($dropboxId == 1) { $userConfig[0] = 1; } else { $userConfig[0] = 0; } if ($googleDriveId == 1) { $userConfig[1] = 1; } else { $userConfig[1] = 0; } return view('pages.home')->with('userConfig', $userConfig); }); Route::post('/save', 'EditController@closeEditor'); Route::post('edit', 'EditController@openEditor'); Route::get('/dropbox', function () {
public function getGoogleDriveClient() { $userId = GoogleDrive::where('userId', Auth::id())->first(); $client = new Google_Client(); $client->setApplicationName(APPLICATION_NAME); $client->setScopes(SCOPES); $client->setAuthConfigFile(CLIENT_SECRET_PATH); $client->setAccessType('offline'); $client->setClientId('61413088518-nvuqb0gr82a47stea9os5cctnu35ssp6.apps.googleusercontent.com'); $client->setClientSecret('eEY5p3_oq3L1w7rrVWB6Odw8'); if ($userId) { $access_token = $userId->access_token; $client->setAccessToken($access_token); /* To check whether access token is expired or not */ if ($client->isAccessTokenExpired()) { $refreshToken = $userId->refresh_token; //Here's where the magical refresh_token comes into play $client->refreshToken($refreshToken); /* Setting new Access Token */ $client->setAccessToken($client->getAccessToken()); /* Update the database with new Access Token and refresh token */ DB::table('googleDrive')->where('driveId', $userId->driveId)->update(['access_token' => $client->getAccessToken(), 'refresh_token' => $client->getRefreshToken()]); } //$this->userAlreadyExists($client); } else { $client->authenticate($_GET['code']); $access_token = $client->getAccessToken(); $googleDriveObject = new GoogleDrive(); $googleDriveObject->userId = Auth::id(); $googleDriveObject->access_token = $access_token; $googleDriveObject->refresh_token = $client->getRefreshToken(); $googleDriveObject->save(); $client->setAccessToken($access_token); } $drive_service = new Google_Service_Drive($client); return $drive_service; }