namest/settings
最新稳定版本:v0.1.1
Composer 安装命令:
composer require namest/settings
包简介
README 文档
README
Provide a very flexible way to interact with app settings (not laravel config).
Note: The package is only support Laravel 5
Installation
Step 1: Install package
composer require namest/settings
Step 2: Register service provider in your config/app.php
return [ ... 'providers' => [ ... 'Namest\Settings\SettingsServiceProvider', ], ... 'aliases' => [ ... 'Setting' => 'Namest\Settings\Facades\Setting', ], ];
Step 3: Publish package resources, include: configs, migrations. Open your terminal and type:
php artisan vendor:publish --provider="Namest\Settings\SettingsServiceProvider"
Step 4: Migrate the migration that have been published
php artisan migrate
Step 5: Add some setting key/value pairs in settings table in your database
Step 6: Read API below and start happy
API
Three way to start to use:
First way: New setting instance
$settings = new Namest\Settings\Repository;
Second way: Via facade like this
Setting::get($key);
Setting::set($key, $value);
Third way: Via injected contract. For example in controller:
namespace ...;
use Namest\Settings\Contracts\Repository as Settings;
class UsersController extends Controller
{
private $settings;
public function __construct(Settings $settings)
{
$this->settings = $settings;
}
public function index()
{
$limit = $this->settings->limit;
}
// Or injects via method
public function show(Settings $settings)
{
$limit = $settings->limit;
}
}
// Return all settings Setting::all(); $settings->all(); // Check setting exists Setting::has($key); isset($settings[$key]); array_key_exists($key, $settings); // Get setting value from key Setting::get($key, $default); // Via facade setting($key, $default); // Via helper function $settings[$key]; // Via array access $settings->$key; // Via object access. Example: $limit = $settings->limit; // Set setting value Setting::set($key, $value); $settings[$key] = $value; $settings->$key = $value;
// Reload preloaded settings Setting::preload();
统计信息
- 总下载量: 62
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-01