Skip to content

DTS-And-Eaglepoint-Funding/laravel-config

 
 

Repository files navigation

Laravel Config Logo

Latest Version on Packagist GitHub Workflow Status Quality Score Total Downloads

Introduction

Laravel config provides a simple configuration system for your Laravel application.

Installation

You can install the package via composer:

composer require tarfin-labs/laravel-config

Next, you MUST publish Models, Factories, and Traits When updating you might need to rerun the installation command be warned this will overwrite any changes made to any of the published Models, Factories, and Traits

php artisan laravel-config:install

Next, you should publish the Laravel config migration file using the vendor:publish Artisan command.

php artisan vendor:publish --provider="TarfinLabs\LaravelConfig\LaravelConfigServiceProvider" --tag="laravel-config"

If you want to use Laravel Config database factory, you can publish it too, using the command:

php artisan vendor:publish --provider="TarfinLabs\LaravelConfig\LaravelConfigServiceProvider" --tag="laravel-config-factories"

Finally, you should run your database migrations:

php artisan migrate

Documentation

Simple usage example of laravel-config package in your Laravel app.

Create new config parameter:

$factory = new ConfigFactory();
$configItem = $factory->setName('key')
    ->setType(ConfigDataType::BOOLEAN)
    ->setValue('1')
    ->setTags(['system'])//optional
    ->setDescription('Lorem ipsum dolor sit amet')
    ->get();

LaravelConfig::create($configItem);

Get value with config name:

LaravelConfig::get('key');

Set value with config name and value:

LaravelConfig::set('key', 'value');

Get all config parameters:

LaravelConfig::all();

Get config items by tag:

LaravelConfig::getByTag('key');

Check if the config exists:

LaravelConfig::has('key');

Update config with new values:

$factory = new ConfigFactory($configId);
$configItem = $factory->setName('updated-key')
    ->setType(ConfigDataType::BOOLEAN)
    ->setValue('0')
    ->setTags(['system'])//optional
    ->setDescription('updated description')
    ->get();

LaravelConfig::update_config($configItem);

Remove config:

LaravelConfig::delete_config('key');

Nested Parameters

Let's say you have a config parameters named foo.bar and foo.baz. You can get all parameters under foo namespace using getNested() method.

Usage:

LaravelConfig::getNested('foo');

Output: Illuminate\Support\Collection

=> Illuminate\Support\Collection {#3048
     all: [
       TarfinLabs\LaravelConfig\Config\Config {#3097
         id: 1,
         name: "bar",
         type: "boolean",
         val: "0",
         description: null,
         created_at: "2021-05-06 11:35:05",
         updated_at: "2021-05-06 11:35:05",
       },
       TarfinLabs\LaravelConfig\Config\Config {#3099
         id: 2,
         name: "baz",
         type: "boolean",
         val: "1",
         description: null,
         created_at: "2021-05-06 11:03:48",
         updated_at: "2021-05-06 11:03:48",
       },
     ],
   }

Helpers

You can also use helper functions:

// Creating config item
$factory = new ConfigFactory();
$configItem = $factory->setName('key')
    ->setType(ConfigDataType::BOOLEAN)
    ->setValue('1')
    ->setTags(['system'])//optional
    ->setDescription('Lorem ipsum dolor sit amet')
    ->get();

create_config($configItem);

// Reading config item
read_config('key');

// Checking if the config item exists
has_config('key');

// Shortcut to update the value of config item
set_config_value('key', 'value');

// Updating config item
$factory = new ConfigFactory($configId);
$configItem = $factory->setName('updated-key')
    ->setType(ConfigDataType::BOOLEAN)
    ->setTags(['system'])//optional
    ->setValue('0')
    ->setDescription('updated description')
    ->get();

update_config($configItem);

// Removing config item
delete_config('key');

// Reading nested config items
read_nested('foo.bar');

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Security

If you discover any security related issues, please email development@tarfin.com instead of using the issue tracker.

Credits

License

Laravel config is open-sourced software licensed under the MIT license.

About

Key value config management for Laravel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%