Laravel Persistent Configuration

News

June 12th, 2019

laravel-config.jpg

Laravel Persistent Configuration is a package by Paul Klimov that provides persistent configuration for Laravel.

This extension allows reconfiguration of already created config repository using data from the external storage like relational database. It provides special config repository class, which wraps any given config repository, adding a layer for saving and restoring of data from persistent storage.

The package’s PersistentRepository class fully decorates any configuration repository implementing the \Illuminate\Contracts\Config\Repository interface. For example, the readme illustrates extending the Illuminate\Config\Repository service:

1use Illuminatech\Config\StorageDb;
2use Illuminate\Support\ServiceProvider;
3use Illuminate\Contracts\Config\Repository;
4use Illuminatech\Config\PersistentRepository;
5
6// ...
7
8$this->app->extend('config', function (Repository $originConfig) {
9 $storage = new StorageDb($this->app->make('db.connection'));
10
11 $newConfig = (new PersistentRepository($originConfig, $storage))
12 ->setItems([
13 'mail.contact.address' => [
14 'label' => __('Email address receiving contact messages'),
15 'rules' => ['sometimes', 'required', 'email'],
16 ],
17 // ...
18 ]);
19
20 return $newConfig;
21});

This package includes multiple storage options for saving and retrieving config values. Out of the box, the package consists of generic database storage, eloquent storage (stores configuration in Eloquent models), PHP, an array.

You can learn more about this package, get full installation instructions, and view the source code on GitHub at illuminatech/config.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.