https://github.com/nzsakib/db-config
Package for storing laravel config details in database
https://github.com/nzsakib/db-config
configuration-management database environment laravel php
Last synced: 4 months ago
JSON representation
Package for storing laravel config details in database
- Host: GitHub
- URL: https://github.com/nzsakib/db-config
- Owner: nzsakib
- License: mit
- Created: 2019-12-24T13:46:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-04T09:39:27.000Z (over 6 years ago)
- Last Synced: 2025-02-27T23:08:05.502Z (over 1 year ago)
- Topics: configuration-management, database, environment, laravel, php
- Language: JavaScript
- Size: 326 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Very short description of the package
[](https://packagist.org/packages/nzsakib/db-config)
[](https://travis-ci.org/nzsakib/db-config)
[](https://scrutinizer-ci.com/g/nzsakib/db-config)
[](https://packagist.org/packages/nzsakib/db-config)
This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
## Installation
You can install the package via composer:
```bash
composer require nzsakib/db-config
```
## Usage
#### Facade or Implementation Class?
You can either use facade or direct implementation class to work.
```php
// You can use following facade
\Nzsakib\DbConfig\Facades\CustomConfig::getCollection();
// Or you can use the implementation below
(new \Nzsakib\DbConfig\DbConfig())->getCollection();
```
#### Get All Configurations as collection from DB
```php
use Nzsakib\DbConfig\DbConfig;
$config = new DbConfig;
$allConfig = $config->getCollection(); // returns Model collection of specified table
// pass to blade or do your thing by looping
foreach($allConfig as $config) {
dump($config->name);
dump($config->value);
}
```
#### Set a new config
``` php
use Nzsakib\DbConfig\DbConfig;
$config = new DbConfig;
$name = 'facebook';
$value = [
'client_id' => 'a client id',
'client_secret' => 'client secret',
];
// Value could be any data type e.g. boolean/array/string/integer
try {
$newConfig = $config->set($name, $value);
// new config is set and cache is invalidated
} catch (\InvalidArgumentException $e) {
// redirect with message $e->getMessage()
}
```
#### Update existing DB config
Cache will be deleted automatically after successfull update.
```php
use Nzsakib\DbConfig\DbConfig;
use Illuminate\Database\Eloquent\ModelNotFoundException;
$config = new DbConfig;
$name = 'facebook';
$newValue = [
'client_id' => 'updated client id',
'client_secret' => 'updated secret'
];
try {
$updatedConfig = (new DbConfig)->updateByName($name, $newValue);
// Updated model is returned
} catch (ModelNotFoundException $e) {
// Specified name does not exists in database
}
// Or you could update by `id` which is primary key
try {
$updatedConfig = (new DbConfig)->updateById($id, $name, $newValue);
// Updated model is returned
} catch (ModelNotFoundException $e) {
// Specified id does not exists in database
}
```
#### Delete a DB Config
Cache will be deleted automatically after successfull delete.
```php
use Nzsakib\DbConfig\DbConfig;
use Illuminate\Database\Eloquent\ModelNotFoundException;
$name = 'facebook';
try {
$deletedConfig = (new DbConfig)->deleteByName($name);
// deleted successfully
} catch (ModelNotFoundException $e) {
// specified name does not exists in database
}
// Or delete the config by primary key `id`
$id = request('id');
try {
$deletedConfig = (new DbConfig)->deleteById($id);
// deleted successfully
} catch (ModelNotFoundException $e) {
// specified id does not exists in database
}
```
#### Get Eloquent DB Query to Work With Data
```php
use Nzsakib\DbConfig\DbConfig;
$query = (new DbConfig)->getQuery();
// Returns Builder instance to underlying config table Model
// You can run custom query on it
$query->where('name', 'facebook')->delete();
// facebook config row is deleted from DB
```
## Publish the package config and migration files
```bash
php artisan vendor:publish --provider="Nzsakib\DbConfig\DbConfigServiceProvider" --tag="config"
php artisan vendor:publish --provider="Nzsakib\DbConfig\DbConfigServiceProvider" --tag="migrations"
```
You can change table name of the migration file, but make sure you mention the updated table name in the config file.
### Testing
``` bash
composer test
```
### Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you discover any security related issues, please email sukku.mia@gmail.com instead of using the issue tracker.
## Credits
- [Nazmus Sakib](https://github.com/nzsakib)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
## Laravel Package Boilerplate
This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).