mschinis / settings
该包最新版本(dev-master)没有可用的许可信息。
dev-master
2015-04-09 00:43 UTC
Requires
- php: >=5.4.0
- illuminate/support: 4.2.*
This package is not auto-updated.
Last update: 2024-09-28 17:07:24 UTC
README
Web 应用程序的设置。Laravel 的一个简单而强大的方式来存储和检索数据库中的设置。使用 Settings 存储网站标题或开发过程中使用的通用变量等,并希望使这些值的修改变得简单。
将其与后端页面结合使用,可以随时添加/修改/删除设置,这样你就拥有了完美的设置页面。
安装
在 Laravel 项目的 composer.json 文件中,将 settings
添加为 require 对象中的依赖
"mschinis/settings": "dev-master"
使用 composer update
更新依赖项并下载包。
安装完成后,将 ServiceProvider 添加到 provider 数组中,并将 Setting 别名添加到 app/config/app.php 中的 aliases 数组中
'providers' => array( 'Mschinis\Settings\SettingsServiceProvider' ) 'aliases' => array( 'Setting' => 'Mschinis\Settings\Facades\Setting' )
设置数据库表就像 1-2-3 一样简单。
- 使用
php artisan migrate:publish mschinis/settings
将迁移文件发布到迁移目录 - 使用
php artisan migrate
运行迁移
等等,没有第 3 步?是的。就这样了!享受使用设置包吧 :)
用法
该包仅在数据库中存储设置,但很快将添加更多设置存储,如 redis/json 文件。默认表是 settings
。如果您想修改表名,可以使用 php artisan config:publish mschinis/settings
发布配置文件,并在发布的配置文件中更改表名。
您可以通过它的外观访问设置存储。以下是一个简单的使用示例。
<?php Setting::set('app.title', 'My awesome website'); // Set a new setting / Update an existing setting $title_setting = Setting::get('app.title', 'default value'); // Retrieve the value of a setting, with a default fallback $title_setting = Setting::get('app.title'); // Retrieve the value of a setting with no default fallback $title_object = Setting::getObject('app.title') // Retrieve the Eloquent object model of the 'app.title' setting. Setting::forget('app.title'); // Remove a setting from the database $settings = Setting::all(); // Retrieve all settings from the database ?>
如果包无法找到特定的设置,并且未提供默认值,则会抛出异常。要处理异常,您可以使用
<?php try{ $title_setting = Setting::get('app.title'); }catch(Exception $e){ // Handle error here. } ?>
未来工作
- 对各种额外字段,如描述,提供多语言支持。
- 不同的存储机制,如 redis/json 文件。
- 支持 Laravel 5。
- 想添加其他功能?请在 Github 上创建问题!
联系方式
如果您有任何问题或建议,请在 GitHub 上创建问题。
许可证
本存储库的内容根据 MIT 许可证 发布。