A dynamic parameter management package for Laravel that provides a simple and flexible way to define, store, and retrieve typed configuration values.
adolfoholzer/parameters is a Laravel package for a dynamic parameter management package for laravel that provides a simple and flexible way to define, store, and retrieve typed configuration values..
It currently has 0 GitHub stars and 1 downloads on Packagist (latest version V1.0.0).
Install it with composer require adolfoholzer/parameters.
Discover more Laravel packages by adolfoholzer
or browse all Laravel packages to compare alternatives.
Last updated
A dynamic parameter management package for Laravel that provides a simple and flexible way to define, store, and retrieve typed configuration values.
You can install the package via Composer:
composer require adolfoholzer/parameters
You may publish all of the package's resources at once:
php artisan vendor:publish --tag="parameters"
Or, you may publish each resource individually:
php artisan vendor:publish --tag="parameters-config"
php artisan vendor:publish --tag="parameters-migrations"
php artisan migrate
The package supports two types of parameters:
All values are stored with an explicit type and automatically cast back to their corresponding native type when retrieved.
Use the Parameters Facade to manage global configuration:
use Parameters;
use Zitro\Parameters\Enums\ParameterType;
Parameters::set(
'site_iva',
22.5,
ParameterType::FLOAT,
'General sales tax rate'
);
Parameters::set(
'maintenance_mode',
true,
ParameterType::BOOLEAN
);
Parameters::set(
'allowed_countries',
['UY', 'AR', 'BR'],
ParameterType::JSON
);
Values are automatically returned with their corresponding native type.
$iva = Parameters::get('site_iva');
// float(22.5)
$maintenance = Parameters::get('maintenance_mode');
// bool(true)
$countries = Parameters::get('allowed_countries');
// ['UY', 'AR', 'BR']
$logo = Parameters::get(
'site_logo',
'default-logo.png'
);
Parameters::forget('site_iva');
The associated cache entry will be automatically invalidated.
You can store configuration values for any entity in your application.
For example:
Add the HasParameters trait to your model:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Zitro\Parameters\Traits\HasParameters;
class Team extends Model
{
use HasParameters;
}
use Zitro\Parameters\Enums\ParameterType;
$team = Team::find($id);
$team->setParameter(
'max_users',
15,
ParameterType::INT,
'Maximum number of subscribed users'
);
$team->setParameter(
'modules_enabled',
['crm', 'billing'],
ParameterType::JSON
);
$maxUsers = $team->getParameter('max_users');
// int(15)
$modules = $team->getParameter('modules_enabled');
// ['crm', 'billing']
$team->forgetParameter('max_users');
The package provides native support for:
| Type | Returned Value | | ------- | -------------- | | STRING | string | | INT | int | | FLOAT | float | | BOOLEAN | bool | | JSON | array |
Values are automatically cast using the type defined when the parameter is stored.
To minimize repeated database queries, the package includes a transparent caching layer.
Features:
Configuration:
'use_cache' => true,
'cache_ttl' => 3600,
Please see CHANGELOG for more information on what has changed recently.
Thank you for considering contributing to Parameters! Please review our contributing guide to get started.
Please review our security policy on how to report security vulnerabilities.
Parameters is open-sourced software licensed under the MIT license.