PHPackages                             elafries/firestore-model - 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. elafries/firestore-model

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

elafries/firestore-model
========================

A firestore model for laravel or lumen

v1.0.12(4y ago)043MITPHP

Since May 20Pushed 4y agoCompare

[ Source](https://github.com/elafries/firestore-model)[ Packagist](https://packagist.org/packages/elafries/firestore-model)[ RSS](/packages/elafries-firestore-model/feed)WikiDiscussions master Synced 2d ago

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

FirestoreModel for laravel or lumen
===================================

[](#firestoremodel-for-laravel-or-lumen)

Initilaization
--------------

[](#initilaization)

### Set up credential file

[](#set-up-credential-file)

Create and download a credential for service account
[https://console.firebase.google.com/u/0/project/`${PROJECT\_ID}`/settings/serviceaccounts/adminsdk](https://console.firebase.google.com/u/0/project/%60$%7BPROJECT_ID%7D%60/settings/serviceaccounts/adminsdk)
Copy the credential.json of the service account to root directory eg: `firebase-credential.json`

### Set up `.env`

[](#set-up-env)

```
GOOGLE_CLOUD_PROJECT=google-project-id
GOOGLE_APPLICATION_CREDENTIALS=/absolute/path/to/credential/file.json

```

### Register service provider

[](#register-service-provider)

Add this line to `bootstrap/app.php`
`$app->register(Kreait\Laravel\Firebase\ServiceProvider::class);`

Creating a model
----------------

[](#creating-a-model)

This will create a model, which will connect to the `users` table

```
use Elafries\FirestoreModel\FirestoreModel;

class User extends FirestoreModel {

}
```

### Handle model fields

[](#handle-model-fields)

```
use Elafries\FirestoreModel\FirestoreModel;

class User extends FirestoreModel {

    protected ?string $table = 'user';

    protected array $fillable = [
       'name', 'age', 'weight'
    ];

    protected array $hidden = [
        'password',
    ];

    protected array $secure = [
        'password',
    ];
}
```

#### `table`

[](#table)

This is an optional parameter.
The name will be generated from the lowercase classname joined with underscores. eg:
`ThisIsATable >> this_is_a_table`
If you fill the `$table` variable the table name will be overriden by its value.

#### `fillable`

[](#fillable)

When you insert to the database these fields will be added and the `secure` fields **ONLY**!

#### `hidden`

[](#hidden)

When you fetch from the database, these fields will be hidden

#### `secure`

[](#secure)

When you insert/update the database these fields will be encrypted.
When you insert to the database, it will extend the fillable parameters.

### Using a model via dependency injection

[](#using-a-model-via-dependency-injection)

```
class UserController extends Controller
{
    public function __construct(private User $user) {}
}
```

Queries
-------

[](#queries)

### List queries

[](#list-queries)

#### Fetch all item in the database `:array`

[](#fetch-all-item-in-the-database-array)

```
$this->user->all();
```

#### Fetch items in the database with filtering `:array`

[](#fetch-items-in-the-database-with-filtering-array)

```
$this->user->where('name', '=', 'test')->get();
```

#### Fetch items in the database with multiple where filtering `:array`

[](#fetch-items-in-the-database-with-multiple-where-filtering-array)

```
$this->user
    ->where('name', '=', 'test')
    ->where('age', '>', '33')
    ->where('weight', '>', '110')
    ->get();
```

#### Fetch items in the database with filtering and with all the hidden properties `:array`

[](#fetch-items-in-the-database-with-filtering-and-with-all-the-hidden-properties-array)

```
$this->user->where('name', '=', 'test')->getRaw();
```

### Single result queries

[](#single-result-queries)

#### Fetch the first in the database with filtering `:array`

[](#fetch-the-first-in-the-database-with-filtering-array)

```
$this->user
    ->where('name', '=', 'test')
    ->where('age', '>', '33')
    ->first();
```

#### Fetch the first in the database with filtering and with all the hidden properties `:array`

[](#fetch-the-first-in-the-database-with-filtering-and-with-all-the-hidden-properties-array)

```
$this->user
    ->where('name', '=', 'test')
    ->where('age', '>', '33')
    ->firstRaw();
```

#### Fetch the first in the database by id `:array`

[](#fetch-the-first-in-the-database-by-id-array)

```
$this->user->findById('2asd123a23a');
```

#### Fetch the first in the database by id, with all the hidden properties `:array`

[](#fetch-the-first-in-the-database-by-id-with-all-the-hidden-properties-array)

```
$this->user->findByIdRaw('2asd123a23a');
```

### Existence queries

[](#existence-queries)

#### Count all items in a query `:int`

[](#count-all-items-in-a-query-int)

```
$this->user
    ->where('name', '=', 'test')
    ->where('age', '>', '33')
    ->count();
```

#### Check if there is at least one result (exists) `:bool`

[](#check-if-there-is-at-least-one-result-exists-bool)

```
$this->user
    ->where('name', '=', 'test')
    ->where('age', '>', '33')
    ->exists();
```

Insert `:array`
---------------

[](#insert-array)

```
$this->user->create([
    'name' => 'Bill Buffalo',
    'age' => 43,
    'weight' => 92,
    'password' => 'secret'
]);
```

Update
------

[](#update)

### Update by id `:void`

[](#update-by-id-void)

```
$this->user->updateById('2asd123a23a', [
    'age' => 51,
    'weight' => 97,
]);
```

### Update all which match the query `:void`

[](#update-all-which-match-the-query-void)

```
$this->user
    ->where('name', '=', 'test')
    ->where('age', '>', '33')
    ->update([
        'age' => 51,
        'weight' => 97,
    ]);
```

Delete
------

[](#delete)

### Delete all which match the query `:void`

[](#delete-all-which-match-the-query-void)

```
$this->user
    ->where('name', '=', 'test')
    ->where('age', '>', '33')
    ->delete();
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~4 days

Recently: every ~13 days

Total

13

Last Release

1766d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21121648?v=4)[Bereczky Balázs](/maintainers/bereczkybalazs)[@bereczkybalazs](https://github.com/bereczkybalazs)

---

Top Contributors

[![bereczkybalazs](https://avatars.githubusercontent.com/u/21121648?v=4)](https://github.com/bereczkybalazs "bereczkybalazs (30 commits)")

### Embed Badge

![Health badge](/badges/elafries-firestore-model/health.svg)

```
[![Health](https://phpackages.com/badges/elafries-firestore-model/health.svg)](https://phpackages.com/packages/elafries-firestore-model)
```

###  Alternatives

[kitar/laravel-dynamodb

A DynamoDB based Eloquent model and Query builder for Laravel.

193675.3k1](/packages/kitar-laravel-dynamodb)[firevel/firequent

Limited implementation of Eloquent based on Firestore.

267.1k](/packages/firevel-firequent)[beebmx/kirby-db

Enable database support for Illuminate\\Database in Kirby

192.6k](/packages/beebmx-kirby-db)

PHPackages © 2026

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