PHP code example of elafries / firestore-model

1. Go to this page and download the library: Download elafries/firestore-model library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

elafries / firestore-model example snippets



use Elafries\FirestoreModel\FirestoreModel;

class User extends FirestoreModel {

}


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',
    ];
}
 

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


$this->user->all();

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

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

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

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

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

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

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

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

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

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

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

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

$this->user
    ->where('name', '=', 'test')
    ->where('age', '>', '33')
    ->delete();
$app->register(Kreait\Laravel\Firebase\ServiceProvider::class);