Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LYiub's avatar
Level 1

Get the data from Google spread sheet in Laravel

I'm trying to get the data from Google spread sheet by using this library: " https://github.com/kawax/laravel-google-sheets/ ", and I follow this tutorial to configure the setup of API and no any error, but once I tried to implement any of the examples they provide in the above link, it show me some errors:

Example 1 (on their link):

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PulkitJalan\Google\Facades\Google;
use Revolution\Google\Sheets\Sheets;

class SpreadController extends Controller
{
    function index()
    {
        $rows = Sheets::sheet('Sheet 1')->get();

        $header = $rows->pull(0);
        $values = Sheets::collection($header, $rows);
        dd($values);
    }

}

The error is:

Unresolvable dependency resolving [Parameter #0 [ array $config ]] in class PulkitJalan\Google\Client

Example 2 (on their link):

Code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PulkitJalan\Google\Facades\Google;
use Revolution\Google\Sheets\Sheets;

class SpreadController extends Controller
{
    function index()
    {
        $user = $request->user();

        $token = [
            'access_token'  => $user->access_token,
            'refresh_token' => $user->refresh_token,
            'expires_in'    => $user->expires_in,
            'created'       => $user->updated_at->getTimestamp(),
        ];

// all() returns array
        $values = Sheets::setAccessToken($token)->spreadsheet('1n0nyJYp-_frg7TzoyMu3WyCo21g')->sheet('Sheet 1')->all();

    }

}

The error is:

Undefined variable: request

This is the config file in the library directory ("vendor/pulkitjalan/google-apiclient/src/config/config.php"):

<?php

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

    /*
    |----------------------------------------------------------------------------
    | 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', ''),
    'client_secret'   => env('GOOGLE_CLIENT_SECRET', ''),
    '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
        */
        'file' => env('GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION', '')
    ],

    /*
    |----------------------------------------------------------------------------
    | 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' => [],
];

and .env file contains this assigned values for the config variables:

GOOGLE_APPLICATION_NAME= Append Data
 GOOGLE_CLIENT_ID= 995576272219-q9tul4g67ufveprhoctcq7g.apps.googleusercontent.com
 GOOGLE_CLIENT_SECRET= ow1kEPcXFxguSEGIXZtl
 GOOGLE_REDIRECT=
 GOOGLE_DEVELOPER_KEY=
 GOOGLE_SERVICE_ENABLED=
 GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION= 

Can anyone guide me through the solution how I can get the data from spreadsheet or solve the problem considered here.

0 likes
3 replies
burlresearch's avatar

Your link isn't working - but that's not the issue.

In order to re-create a spread-sheet in Laravel then you will inevitably generate column-based data in many rows. Each column is defined by a migration:

http://laravel.test/docs/master/migrations

Building an appropriate table for your sheet, and importing the data-rows, is what you want...

LYiub's avatar
Level 1

Thanks for your response, I update the link, as I need to get the data of Google spread sheet in Laravel.

burlresearch's avatar
Level 40

For your 1st issue: did you run the artisan vendor:publish as the document specifies. The error seems to refer to that.

2nd, I think all you need to do is to type-hint the

function index(Request $request)

Please or to participate in this conversation.