-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(System): configuration option firebase to store data
- composer require kreait/laravel-firebase - php artisan route:cache see #34
- Loading branch information
tuannt
committed
Nov 12, 2020
1 parent
0ae1874
commit ae0e7be
Showing
6 changed files
with
158 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace GGPHP\Config\Services; | ||
|
||
use GGPHP\Config\Models\GGConfig; | ||
|
||
class FirebaseService { | ||
|
||
protected $database; | ||
|
||
public function __construct() | ||
{ | ||
$this->database = app('firebase.database'); | ||
} | ||
|
||
/** | ||
* This function use to get reference | ||
* @param string $reference | ||
* @return object | ||
*/ | ||
public function retrieveData($reference = null) | ||
{ | ||
return $reference ? $this->database->getReference($reference) : $this->database->getReference(); | ||
} | ||
|
||
/** | ||
* This function use to add data in firebase | ||
* @param string $reference | ||
* @param object $data | ||
* @return object | ||
*/ | ||
public function addData($reference = null, $data) | ||
{ | ||
$firebase = $this->retrieveData($reference); | ||
|
||
return $firebase->push($data); | ||
} | ||
|
||
/** | ||
* This function use to set data in firebase | ||
* @param string $reference | ||
* @param object $data | ||
* @return object | ||
*/ | ||
public function setData($reference = null, $data) | ||
{ | ||
$firebase = $this->retrieveData($reference); | ||
|
||
return $firebase->set($data); | ||
} | ||
|
||
/** | ||
* This function use to get data config info by code | ||
* @param code field $code | ||
* @return object | ||
*/ | ||
public function getDataByCode($code) | ||
{ | ||
$reference = $this->retrieveData(GGConfig::FIELD_REFERENCE); | ||
$data = $reference->getValue() ?? []; | ||
$configs = []; | ||
|
||
foreach($data as $value) { | ||
if (isset($value['code']) && $value['code'] == $code) | ||
$configs = $value; | ||
} | ||
|
||
return $configs; | ||
} | ||
} |