LaravelPackages.net
Acme Inc.
Toggle sidebar
adolfoholzer/parameters

A dynamic parameter management package for Laravel that provides a simple and flexible way to define, store, and retrieve typed configuration values.

1
0
V1.0.0
About adolfoholzer/parameters

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

Parameters

Packagist PHP from Packagist Laravel versions GitHub Workflow Status (main) Total Downloads

A dynamic parameter management package for Laravel that provides a simple and flexible way to define, store, and retrieve typed configuration values.

Installation

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:

Publishing the Configuration File

php artisan vendor:publish --tag="parameters-config"

Publishing and Running the Migrations

php artisan vendor:publish --tag="parameters-migrations"
php artisan migrate

Usage

Basic Usage

The package supports two types of parameters:

  • Global system parameters
  • Parameters associated with specific models

All values are stored with an explicit type and automatically cast back to their corresponding native type when retrieved.

Global Parameters

Use the Parameters Facade to manage global configuration:

use Parameters;
use Zitro\Parameters\Enums\ParameterType;

Storing Parameters

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
);

Retrieving Parameters

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']

Default values

$logo = Parameters::get(
    'site_logo',
    'default-logo.png'
);

Removing parameters

Parameters::forget('site_iva');

The associated cache entry will be automatically invalidated.

Model-Specific Parameters

You can store configuration values for any entity in your application.

For example:

  • Users
  • Teams
  • Customers
  • Projects
  • Organizations

Preparing a Model

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;
}

Storing Parameters

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
);

Retrieving Parameters

$maxUsers = $team->getParameter('max_users');
// int(15)

$modules = $team->getParameter('modules_enabled');
// ['crm', 'billing']

Removing Parameters

$team->forgetParameter('max_users');

Supported Types

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.

Caching

To minimize repeated database queries, the package includes a transparent caching layer.

Features:

  • Independent caching for global parameters
  • Segmented caching for polymorphic parameters
  • Automatic cache invalidation when values are updated
  • Configurable TTL

Configuration:

'use_cache' => true,
'cache_ttl' => 3600,

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Thank you for considering contributing to Parameters! Please review our contributing guide to get started.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

Parameters is open-sourced software licensed under the MIT license.

Comments