alisaleem / laravel-settings
File based configurable settings for laravel applications
Fund package maintenance!
Ali Saleem
Requires
- php: ^8.2
- spatie/laravel-package-tools: ^1.14.0
- spatie/valuestore: ^1.3
Requires (Dev)
- orchestra/testbench: ^8.8
- pestphp/pest-plugin-laravel: ^2.0
README
Store your application settings in any of your applications storage filesystems. The schema for the settings is defined by a normal PHP class and all primitive types are supported. This also provides IDE type hints when reading to writing settings.
Updated values are written to the filesystem on destruct.
Installation
You can install the package via composer:
composer require alisaleem/laravel-settings
Create your own Settings class and extend the abstract Settings class from this package
namespace App; class MySettings extends \AliSaleem\LaravelSettings\BaseSettings { public string $key; public string $anotherKey = 'Default Value'; }
Optionally add the helper function. This will also provide IDE type-hinting
if (! function_exists('settings')) { function settings(): \App\MySettings { return resolve(config('settings.class')); } }
You can publish the config file with:
php artisan vendor:publish --tag="settings-config"
Set the class and storage location in the config file
return [ 'class' => \App\MySettings::class, 'storage' => [ 'disk' => null, 'path' => 'settings.json', ], ];
Usage
// To retrieve a value $value = resolve(\App\MySettings::class)->key; $value = settings()->anotherKey; // To set a value resolve(\App\MySettings::class)->key = 'changed'; settings()->anotherKey = 'changed';
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.