I need to link Google Sheet with my Laravel



PHP Snippet 1:

<?php
    
namespace App\Http\Controllers;
    
use Revolution\Google\Sheets\Facades\Sheets;
    
class MagicViewController extends Controller
{
  public function google()
  {
    
    
  // Add new sheet to the configured google spreadsheet
  Sheets::spreadsheet('19eKwKwxxxKsd6cSM')->addSheet('sheet 3');
    
    
  $rows = [
  ['1', '2', '3'],
  ['4', '5', '6'],
  ['7', '8', '9'],
  ];
    
    
  // Append multiple rows at once
  Sheets::sheet('sheetTitle')->append($rows);
    
return view('magic_view');
    
  } 
}

PHP Snippet 2:

GOOGLE_APPLICATION_NAME=MyApp
SPREADSHEET_ID=19eKwKwM0wGhXXXXXXXXXd6cSM
GOOGLE_CLIENT_ID=2410oksuct.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=XXXXXXXXX3IFqwVsd7kYFXXXbWd
GOOGLE_REDIRECT=
GOOGLE_DEVELOPER_KEY=
GOOGLE_SERVICE_ENABLED=true
GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION=./storage/credentials.json
GOOGLE_APPLICATION_CREDENTIALS=./storage/credentials.json

PHP Snippet 3:

<?php

return [
    /*
    |----------------------------------------------------------------------------
    | Google application name
    |----------------------------------------------------------------------------
    */
    'application_name' => env('GOOGLE_APPLICATION_NAME', 'MyApp'),

    /*
    |----------------------------------------------------------------------------
    | Google OAuth 2.0 access
    |----------------------------------------------------------------------------
    |
    | Keys for OAuth 2.0 access, see the API console at
    | https://developers.google.com/console
    |
    */
    'client_id' => env('GOOGLE_CLIENT_ID', '2410oksuct.apps.googleusercontent.com'),
    'client_secret' => env('GOOGLE_CLIENT_SECRET', 'XXXXXXXXX3IFqwVsd7kYFXXXbWd'),
    'redirect_uri' => env('GOOGLE_REDIRECT', ''),
    'scopes' => [],
    'access_type' => 'online',
    'approval_prompt' => 'auto',

    /*
    |----------------------------------------------------------------------------
    | Google developer key
    |----------------------------------------------------------------------------
    |
    | Simple API access key, also from the API console. Ensure you get
    | a Server key, and not a Browser key.
    |
    */
    'developer_key' => env('GOOGLE_DEVELOPER_KEY', ''),

    /*
    |----------------------------------------------------------------------------
    | Google service account
    |----------------------------------------------------------------------------
    |
    | Set the credentials JSON's location to use assert credentials, otherwise
    | app engine or compute engine will be used.
    |
    */
    'service' => [
        /*
        | Enable service account auth or not.
        */
        'enable' => env('GOOGLE_SERVICE_ENABLED', false),

        /*
         * Path to service account json file. You can also pass the credentials as an array
         * instead of a file path.
         */
        'file' => env('GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION', './storage/credentials.json'),
    ],

    /*
    |----------------------------------------------------------------------------
    | Additional config for the Google Client
    |----------------------------------------------------------------------------
    |
    | Set any additional config variables supported by the Google Client
    | Details can be found here:
    | https://github.com/google/google-api-php-client/blob/master/src/Google/Client.php
    |
    | NOTE: If client id is specified here, it will get over written by the one above.
    |
    */
    'config' => [

        'spreadsheet_id'=> '19eKwKwM0wGhXXXXXXXXXd6cSM',
        // 'google_application_credentials'=> './storage/credentials.json',
    ],
];

PHP Snippet 4:

<?php

namespace App\Services;


use Google_Client;
use Google_Service_Sheets;
use Google_Service_Drive ;
use Google_Service_Sheets_ValueRange;
use App\Models\Api\SheetAuth as ApiSheetAuth;
use App\Models\Colis;
use Google\Service\ServiceControl\Auth;
use App\Models\TemplateFields;
use App\Http\Controllers\callcenter\DispatchCallsController as CallCenter;

class GoogleSheet
{
    private $spreadSheetId;

    private $client;

    public $googleSheetService;

    public function __construct()
    {
       // $this->spreadSheetId = config('datastudio.google_sheet_id');

        $this->client = new Google_Client();
        $this->client->setAuthConfig(storage_path('credentials.json'));
        $this->client->addScope("https://www.googleapis.com/auth/spreadsheets");

        

        $this->googleSheetService = new Google_Service_Sheets($this->client);
    }