letsgoi / laravel-settings
Laravel settings package
Installs: 1 960
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 6
Forks: 0
Open Issues: 0
Requires
- php: ^8.3
- illuminate/database: ^10.0|^11.0
- illuminate/http: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- letsgoi/php-code-style: ^1.2
- orchestra/testbench: ^9.1
- phpunit/phpunit: ^11.2
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::class
toapp.php
/* * Package Service Providers... */ ... Letsgoi\LaravelSettings\SettingsServiceProvider::class,
- Publish configuration:
php artisan vendor:publish --provider="Letsgoi\LaravelSettings\SettingsServiceProvider" --tag="migrations"
- Add
SettingNovaResource::class
onNovaServiceProvider.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