PHPackages                             patrikgrinsvall/laravel-import-spreadsheet - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. patrikgrinsvall/laravel-import-spreadsheet

ActiveLibrary[Database &amp; ORM](/categories/database)

patrikgrinsvall/laravel-import-spreadsheet
==========================================

Laravel Artisan command for importing a google docs spreadsheet into database using a model

290PHP

Since Nov 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Patrikgrinsvall/laravel-import-spreadsheet)[ Packagist](https://packagist.org/packages/patrikgrinsvall/laravel-import-spreadsheet)[ RSS](/packages/patrikgrinsvall-laravel-import-spreadsheet/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel import Google Spreadsheet using Eloquent Model
======================================================

[](#laravel-import-google-spreadsheet-using-eloquent-model)

Install
-------

[](#install)

`composer require patrikgrinsvall/laravel-import-spreadsheet`

Usage Examples
--------------

[](#usage-examples)

1. Always create a new record, use the ´Post´ model and dont match against existing record, continue even if there are database errors and also add all values to a json column named json\_data without caching the response

```
    php artisan import:google-spreadsheet \
    -s  \
    --create-new \
    --model=App\\Models\\Post \
    --skip-errors \
    --json-column=json_data \
    --cache-ttl=0

```

2. Always create a new record, use the ´Post´ model and dont match against existing record, save the spreadsheet in `storage_path("mytmpcsv.csv")`

```
php artisan import:google-spreadsheet  \
-s spreadsheetid \
--create-new \
--model=App\\Models\\Post \
--filename=mytmpcsv.csv \

```

3. Import data using ´database\_column´ as unique key, meaning all rows will be matched against database record with this corresponding value from csv, use the ´Post´ model, save all fields as json in column ´post\_attributes´ and dont cache the response

```
php artisan import:google-spreadsheet -s spreadsheetid \
-u="Spreadsheet header column=datebase_column"  \
--model=App\\Models\\Post \
--json-column=post_attributes \
--cache-ttl=0

```

Running from command line
-------------------------

[](#running-from-command-line)

`php artisan import:google-spreadsheet`

Options

- `-s --spreadsheet=   : The id of the spreadsheet, the character sequence after /d/ in the spreadsheet URL. The spreadsheet must be made public, ` - *required*
- `-m --model=         : The model to use. The columns in the spreadsheet must match the columns snake_case in the model or else they are silently skipped` - *required*
- `-u --unique-key=    : eg. title=identifier, this will take header column in csv and match against the column identifier in the model which must be unique ` - *optional*
- `-j --json-column=   : If the model has a json column where all data should be put, specify this here. ` - *optional*
- `-c --create-new     : Always create a new record, never match key and try to update` - *optional*
- `-f --filename=      : Use this filename as temporary storage` - *default=import.csv*
- `-d --cache-ttl=     : By default the response from google docs is cached for 3600 seconds, this option changes this value, use 0 to disable cache` - *optional*
- `-e --skip-errors    : Skip errors if possible and continue with next row, such as duplicate key or error when inserting data` - *optional*

Config
------

[](#config)

- If running updates often and only used against one spreadsheet id, it makes sense to run `artisan vendor:publish` and set this id environment variables or the config file.

From `config/import-spreadsheet.php`

```
 /*
    |--------------------------------------------------------------------------
    | Google Spreadsheet ID
    |--------------------------------------------------------------------------
    | This is the google spreadsheet id, it can be taken from url in browser.
    | If importing from multiple spreadsheets across serveral commands
    | dont set this in config
     */
    'spreadsheet' => env('IMPORT_SPREADSHEET_ID', null),
    /*
    |--------------------------------------------------------------------------
    | unique-key
    |--------------------------------------------------------------------------
    | The attribute in model or column in database to use for mapping
    | csv header column. Example:
    | 'csv_email_column=email'
    | will map `csv_email_column` column in spreadsheet against email
    | column in the table
     */
    'unique-key' => env('IMPORT_SPREADSHEET_UNIQUE_KEY', null),
    /*
    |--------------------------------------------------------------------------
    | Model
    |--------------------------------------------------------------------------
    | The FQCN to the model to use, example App\\Models\\User
     */
    'model' => env('IMPORT_SPREADSHEET_MODEL', null),
    /*
    |--------------------------------------------------------------------------
    | Json column
    |--------------------------------------------------------------------------
    | If all csv columns should be mapped into a json column in databse
    | table, this is the database column name
     */
    'json-column' => env('IMPORT_SPREADSHEET_JSON_COLUMN', null),
    /*
    |--------------------------------------------------------------------------
    | cache ttl
    |--------------------------------------------------------------------------
    | By default requests to spreadsheets are cached for an hour, 0 will disable
     */
    'cache-ttl' => env('IMPORT_SPREADSHEET_CACHE_TTL', 3600),
    /*
    |--------------------------------------------------------------------------
    | filename
    |--------------------------------------------------------------------------
    | If the original csv file needs to be processed further by another job
    | this is the filename the downloaded file will have on disk
     */
    'filename' => env('IMPORT_SPREADSHEET_FILENAME', storage_path('csvimport.csv'))

```

Contribute
----------

[](#contribute)

PR´s are very welcome

Compability
-----------

[](#compability)

Only tested with laravel 8.0 and 8.1

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d89250134c8b909b2acb905ec3ac333aaf192bab76dc41912f876ae641a5667?d=identicon)[patrikgrinsvall](/maintainers/patrikgrinsvall)

---

Top Contributors

[![silentpatrik](https://avatars.githubusercontent.com/u/77385235?v=4)](https://github.com/silentpatrik "silentpatrik (9 commits)")[![Patrikgrinsvall](https://avatars.githubusercontent.com/u/2749942?v=4)](https://github.com/Patrikgrinsvall "Patrikgrinsvall (3 commits)")

---

Tags

eloquenteloquent-modelseloquent-ormlaravelphpspreadsheet

### Embed Badge

![Health badge](/badges/patrikgrinsvall-laravel-import-spreadsheet/health.svg)

```
[![Health](https://phpackages.com/badges/patrikgrinsvall-laravel-import-spreadsheet/health.svg)](https://phpackages.com/packages/patrikgrinsvall-laravel-import-spreadsheet)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
