PHPackages                             pelfox/laravel-bigquery - 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. pelfox/laravel-bigquery

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

pelfox/laravel-bigquery
=======================

Laravel BigQuery

v2.0.0(1y ago)46.4k↓39.4%1MITPHPPHP ^8.2

Since Oct 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pelfox8/laravel-bigquery)[ Packagist](https://packagist.org/packages/pelfox/laravel-bigquery)[ RSS](/packages/pelfox-laravel-bigquery/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (14)Used By (0)

Laravel Bigquery
================

[](#laravel-bigquery)

This package allows you to use Query Builder and Eloquent for queries in Bigquery.

### Installation

[](#installation)

```
composer require pelfox/laravel-bigquery

```

### Using

[](#using)

Add code in database config in section 'connections':

```
'bigquery' => [
    'driver' => 'bigquery',
    'database' => '',
    'prefix' => '',
    // default the id of the dataset to request
    'dataset' => 'replace on dataset from bigquery', // required
    //  The full path to your service account credentials .json file retrieved from the Google Developers Console.
    'keyFilePath' => 'path to file', // required
],
```

Facade:

```
\Pelfox\LaravelBigQuery\Facades\BigQuery::dataset('dataset')->...
```

Using in Query Builder or Eloquent:

```
// Query Builder
DB::connection('bigquery')->table('table')->...
#for special dataset
DB::connection('bigquery')->table('dataset.table')->...

// Eloquent
class Table extends Model
{
    protected $connection = 'bigquery';
    #for special dataset
    protected $table = 'dataset.table';

    public $incrementing = false;
    public $timestamps = false;
}
```

### You may be use special Eloquent casts when which work correctly with data types Bigquery:

[](#you-may-be-use-special-eloquent-casts-when-which-work-correctly-with-data-types-bigquery)

Namespace to casts: *\\Pelfox\\LaravelBigQuery\\Eloquent\\Casts*

BigQuery typeCastStringAsString::classBytesAsBytes::classIntegerAsInteger::classFloatAsFloat::classNumericAsNumeric::classBigNumericAsBigNumeric::classBooleanAsBoolean::classTimestampAsTimestamp::classDatetimeAsDateTime::classDateAsDate::classTimeAsTime::classStructAsStruct::classJsonAsJson::classGeographyIf the field is repeated (mode is repeated), you need to pass an additional parameter for Cast ':1'

```
'field' => AsString::class . ':1'
```

then an array of values can be passed to the field value

For struct data type necessary pass a method which return schema array

```
'field' => AsString::class . ':0,getSchemaForFieldColumn'
```

schema for struct field should be the same as in bigquery or there will be an error when inserting data

Example a model with casts:

```
