qh-8 / laravel-options
存储Laravel应用程序选项
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
此包允许您将选项存储在仓库(数据库)中。
安装
您可以通过composer安装此包
composer require qh-8/laravel-options
使用方法
发布迁移文件
php artisan vendor:publish --tag=option-migrations
发布配置文件
php artisan vendor:publish --tag=option-config
通过artisan migrate命令创建options
表
php artisan migrate
基本使用
// 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.
配置
# Enable autoload options only. OPTIONS_ONLY_AUTOLOAD=true # Eager load options. OPTIONS_EAGER_LOAD=true # Custom model OPTIONS_MODEL=App\Models\Option
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
安全
如果您发现任何安全问题,请通过电子邮件 dqh@dinhquochan.com 联系,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。