qh-8 / laravel-options
Store Laravel application options
v2.4.0
2023-08-04 10:40 UTC
Requires
- php: ^8.0|^8.1|^8.2
- doctrine/dbal: ^3.2
- illuminate/database: ^9.0|^10.0
Requires (Dev)
- laravel/pint: ^0.2.4
- mockery/mockery: ^1.4
- orchestra/testbench: ^7.6|^8.0
- phpunit/phpunit: ^9.0|^10.0
README
This package allows you to store options in a repository (database).
Installation
You can install the package via composer:
composer require qh-8/laravel-options
Usage
Publish the migration file
php artisan vendor:publish --tag=option-migrations
Publish the config file
php artisan vendor:publish --tag=option-config
Create the options
table via artisan migrate command
php artisan migrate
Basic usage
// Via helper. option('key', 'default'); // Get an option with default value. option(['key' => 'default']); // Set options. option()->save(); // Delete, update or insert to database. // Via service. $this->app['options']->has('key'); // Check option exists. $this->app['options']->get('key', 'default'); // Get an option with default. $this->app['options']->set('key', 'value'); // Set an option. $this->app['options']->set(['key' => 'value']); // Set many options. $this->app['options']->setMany(['key' => 'value']); // Set many options. $this->app['options']->lock('key'); // Lock an option by key. $this->app['options']->unlock('key'); // Unlock an option by key. $this->app['options']->remove('key'); // Delete an option by key. $this->app['options']->all(); // Get all autoload options. $this->app['options']->toArray(); // Same all(). $this->app['options']->toJSon(); // Same all() but json format. $this->app['options']['key'] // Array access: offsetGet $this->app['options']['key'] = 'value' // Array access: offsetSet. isset($this->app['options']['key']) // Array access: offsetExists. unset($this->app['options']['key']) // Array access: offsetUnset.
Configuration
# Enable autoload options only. OPTIONS_ONLY_AUTOLOAD=true # Eager load options. OPTIONS_EAGER_LOAD=true # Custom model OPTIONS_MODEL=App\Models\Option
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 dqh@dinhquochan.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.