PHP Luminova: Read and Write Firebase Realtime Database Records
Select a Firebase Realtime Database path and read or replace child values with Luminova’s Firebase database wrapper.
Use Luminova\Notifications\Firebase\Database when your application stores JSON data in Firebase Realtime Database. The wrapper uses the Firebase Admin SDK for PHP. Install kreait/firebase-php and configure credentials for the PHP process before creating the wrapper. The project ID identifies the Firebase project, and the database URI comes from your Realtime Database instance. See the Firebase Admin SDK database guide.
Class Definition
- Full namespace:
Luminova\Notifications\Firebase\Database
Properties
database
The Firebase database client initialized by the constructor.
protected ?RealtimeDatabase $database = null;RealtimeDatabase refers to Kreait\Firebase\Contract\Database.
tableName
The database path selected by setTable().
protected string $tableName;Methods
__construct
Connect to a Firebase Realtime Database instance.
public function __construct(string $projectId, string $databaseUri)Parameters:
| Parameter | Type | Description |
|---|---|---|
$projectId | string | Firebase project ID. |
$databaseUri | string | URL of the Realtime Database instance. |
setTable
Select a database path, such as profiles or accounts/profiles. Call this before reading or writing a child.
public function setTable(string $table): selfParameters:
| Parameter | Type | Description |
|---|---|---|
$table | string | Parent path for subsequent operations. |
Return:
self - The current wrapper.
getTable
Read the selected path after calling setTable().
public function getTable(): stringReturn:
string - The selected database path.
get
Read a child under the selected path.
public function get(string $child): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$child | string | Child key to read. |
Return:
mixed - The stored child value, or null if the child is absent.
insert
Write the supplied data to a child under the selected path. If the child already exists, this replaces its stored value.
public function insert(string $rowId, array $data): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$rowId | string | Child key to write. |
$data | array<array-key,mixed> | Complete value to store at the child path. |
Return:
mixed - The result of the Firebase reference write.
update
Replace the complete value at an existing or new child path. Include any fields you want to keep.
public function update(string $rowId, array $data): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$rowId | string | Child key to write. |
$data | array<array-key,mixed> | Complete replacement value. |
Return:
mixed - The result of the Firebase reference write.