wovosoft / settings-manager
Laravel应用程序的设置管理
v1.0
2020-04-12 11:12 UTC
Requires
- php: >=7.2
- illuminate/support: ^7.0
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-19 07:43:44 UTC
README
包描述:请修改
安装
通过composer安装
composer require wovosoft/settings-manager
发布配置文件
发布配置文件。
php artisan vendor:publish --provider="Wovosoft\SettingsManager\ServiceProvider" --tag="config"
发布Vue组件。发布后的组件将被复制到 resources/settings-manager/settings
文件夹。您需要将 Main.vue
组件添加到您的 app.js
文件中。
php artisan vendor:publish --provider="Wovosoft\SettingsManager\ServiceProvider" --tag="resources"
发布迁移
php artisan vendor:publish --provider="Wovosoft\SettingsManager\ServiceProvider" --tag="migrations"
发布种子
php artisan vendor:publish --provider="Wovosoft\SettingsManager\ServiceProvider" --tag="seeds"
用法
默认情况下,所有后端和前端集成都直接提供。但如果您仍然想修改此过程,请在控制器或视图中包含外观 Wovosoft\SettingsManager\Facades\Settings
,并像下面界面中说明的指令一样使用它。
interface SettingsInterface { /** * @param number | string | array $key When Number (ID) is provided Query is operated by find() method, else by * where('key',$key)->first(); for array returns key=>value paired aray * @param string|null $group * @param bool $getModel If true returns Model instead value * @return string | array | null */ public function get($key, string $group = null, bool $getModel = false); /** * @param string | number $key Should be unique value. NOTE: Do not use number for creating new Settings. * Only use it when updating. Otherwise, the numeric value will be used as key's value * @param mixed $value mixed Arrays will be parsed as JSON * @param string|null $group Group Name of the Settings Option * @param string $type bootstrap-vue form fields or any kind of fields you want for front-end. This doesn't * related to backend. In this package we are aiming bootstrap-vue framework for front-end. * @param array $options Options usable for Front-End Manipulation. Like Enum DataType * @param bool $getModel If true returns Model instead value * @param null $model Due the the issue of "key as numeric", $item Model parameter is added. The function * should get the model by id or check if it is instance of the Settings.php Model. If it is already a * model do not find it, just perform the operation * @return mixed */ public function set($key, $value, string $group = null, $type = "b-form-input", $options = [], bool $getModel = false, $model = null); /** * @param array $item ['key'=>string | number,'value'=> mixed, 'group'=>string, type'=>string, 'options'=>string | array] * @param bool $getModel If true returns Model instead value * @return mixed */ public function setArray($item = [], bool $getModel = false); /** * @param array $key_values [['key'=>string | number, 'value'=>mixed, 'group'=>string, type'=>string, 'options'=>string | array]] * @param bool $getModel If true returns Model instead value * @return bool */ public function setBatch($key_values = [], bool $getModel = false); /** * @param string $key * @param string|null $group * @param bool $getModel If true returns Model instead value * @return bool */ public function has($key, string $group = null, bool $getModel = false); /** * @param string | number $key number from ID and $key for key * @param string|null $group * @param bool $getModel If true returns Model instead value * @return bool Found && Deleted Condition applicable. */ public function delete($key, string $group = null, bool $getModel = false); /** * @param string|null $group * @param bool $getModel If true returns Model instead value * @return mixed */ public function all(string $group = null, bool $getModel = false); /** * @param bool $getModel * @return mixed */ public function allGrouped(bool $getModel = false); }
示例
use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Wovosoft\SettingsManager\Facades\Settings; class SettingsController extends Controller { public function set(Request $request) { try { $status = Settings::set( $request->post("key"), $request->post("value"), $request->post("group"), $request->post("type"), $request->post("options"), $request->post("getModel") ?? false, $request->post("id") ?? null ); return response()->json([ "status" => $status, "msg" => $status ? "Successfully Done" : "Failed to perform the operation", "type" => $status ? "success" : "warning", "title" => $status ? "Success" : "Failed" ]); } catch (\Exception $exception) { return response()->json([ "status" => false, "msg" => $exception->getMessage(), "title" => "Failed", "type" => "danger", "file" => $exception->getFile(), "line" => $exception->getLine() ], $exception->getCode()); } } }
安全
如果您发现任何与安全相关的问题,请发送电子邮件至 narayanadhikary24@gmail.com 或在GitHub仓库中创建问题。
致谢
此包借助 wovosoft/crud 构建。