devfactory / variables
Laravel 扩展包,允许网站所有者覆盖特定配置文件中的变量
2.0.6
2016-05-06 19:32 UTC
Requires
- php: >=5.4.0
- illuminate/support: 5.*
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- mockery/mockery: dev-master@dev
README
#Variables
这是一个 Laravel 框架的包,它允许用户通过数据库覆盖指定的一组变量
安装
Laravel 5
使用 Composer,编辑您的 composer.json
文件以要求 devfactory/media
。
"require": {
"devfactory/variables": "2.0.*"
}
然后在终端运行
composer update
然后在您的 app/config/app.php
文件中注册服务提供者
'Devfactory\Variables\VariablesServiceProvider',
和外观
'Variables' => 'Devfactory\Variables\Facades\VariablesFacade',
在您项目的 laravel 文件夹中运行
php artisan vendor:publish
运行迁移以创建数据库表
php artisan migrate
您必须将控制器添加到您的 routes.php 路由中,以便您可以设置自己的 URL/过滤器。
Route::group(array('before' => 'admin-auth'), function() { Route::controller('variables', '\Devfactory\Variables\Controllers\VariablesController'); });
Laravel 4
使用 Composer,编辑您的 composer.json
文件以要求 devfactory/media
。
"require": {
"devfactory/variables": "1.0.*"
}
然后在终端运行
composer update
然后在您的 app/config/app.php
文件中注册服务提供者
'Devfactory\Variables\VariablesServiceProvider',
和外观
'Variables' => 'Devfactory\Variables\Facades\VariablesFacade',
运行迁移以创建数据库表
php artisan migrate --package=devfactory/variables
最后,发布配置以更改文件存储的位置和方式
php artisan config:publish devfactory/variables
您必须将控制器添加到您的 routes.php 路由中,以便您可以设置自己的 URL/过滤器。
Route::group(array('before' => 'admin-auth'), function() { Route::controller('variables', 'Devfactory\Variables\Controllers\VariablesController'); });
用法
访问您在路由文件中设置的 URL,如图所示,您可以看到所有当前变量,并通过输入新值并保存来覆盖它们。
然后您可以通过调用 Variables
外观来使用这些变量
<?php $api_key = Variables::get('api_key'); // da46f8af58aec448c784dd421660f7635d404feb
外观中的其他公共方法包括
<?php // Retrieve an array of all the variables Variables::getAll(); // Set the value of a variable Variables::set('api_key', 'da46f8af58aec448c784dd421660f7635d404feb'); // Unset the value of a variable stored in the DB Variables::remove('api_key');