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.
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',
],
];
// 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';
composer test
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.