nzsakib / db-config
Package for storing config details in database
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:JavaScript
Requires
- php: ^7.1
- illuminate/support: >=5.6.0
Requires (Dev)
- orchestra/testbench: 3.6.*
- phpunit/phpunit: ^7.0
- predis/predis: ^1.1
This package is auto-updated.
Last update: 2024-05-04 19:04:06 UTC
README
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:
composer require nzsakib/db-config
Usage
Facade or Implementation Class?
You can either use facade or direct implementation class to work.
// 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
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
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.
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.
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
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
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
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email sukku.mia@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.