letsgoi/laravel-settings
最新稳定版本:4.0.1
Composer 安装命令:
composer require letsgoi/laravel-settings
包简介
Laravel settings package
README 文档
README
Move your env variables to database to change them easily using laravel nova
Requirements
- PHP >= 8.3
- Laravel >= 10.0
- Laravel nova license registered on project
Installation
- Require package with composer:
composer require letsgoi/laravel-settings
- Add
Letsgoi\LaravelSettings\SettingsServiceProvider::classtoapp.php
/* * Package Service Providers... */ ... Letsgoi\LaravelSettings\SettingsServiceProvider::class,
- Publish configuration:
php artisan vendor:publish --provider="Letsgoi\LaravelSettings\SettingsServiceProvider" --tag="migrations"
- Add
SettingNovaResource::classonNovaServiceProvider.php
protected function resources(): void { Nova::resources([ ... SettingNovaResource::class, ]); }
Usage
This package use cache memory to save variables, instead of retrieving them from database each time you need to use it:
- When you save a variable, cache of this variable is cleared.
- First time you retrieve a variable it is saved to cache.
To register a new variable on Settings:
- Create a migration with the name and key of the variable:
- The available types are: bool, string, float, array
DB::table('settings')->insert([ 'id' => 'APP_URL', 'type' => 'string' ]);
- Run migrations:
php artisan migrate - Access your nova url and fill the variable with the value: For booleans use 0 (false) and 1 (true).
- Use variable in your code using:
$settingRepository = new SettingRepository(); $value = $settingRepository->find('key');
Testing
Run tests:
composer test
统计信息
- 总下载量: 3.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-26