ghprod / laravel-settings by ferrisutanto

Laravel 5 persistent settings in database package
49
4
5
Package Data
Maintainer Username: ferrisutanto
Maintainer Contact: greenhouseprod@gmail.com (Ferri Sutanto)
Package Create Date: 2016-09-09
Package Last Update: 2017-01-11
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:08:16
Package Statistics
Total Downloads: 49
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 4
Total Watchers: 5
Total Forks: 0
Total Open Issues: 1

Laravel Settings

Build Status StyleCI Total Downloads License

Laravel 5 persistent settings in database package

Support Laravel 5.1, 5.2, 5.3

Installation

composer require ferri/laravel-settings

And add service provider to you config/app.php

...

Ferri\LaravelSettings\ServiceProvider::class,

...

Publish config and migration

php artisan vendor:publish --provider="Ferri\LaravelSettings\ServiceProvider" --tag=config
php artisan vendor:publish --provider="Ferri\LaravelSettings\ServiceProvider" --tag=migrations

Cache

You can disable cache when get setting value. Default is true. Cache is inherit from active driver in config/cache.php

'cache' => false,

Usage

Set value

Set setting value

Settings::set('key', 'value');
Settings::set('keyArray', ['arrayKey' => 'arrayValue']);

Get value

Get setting value

Settings::get('key'); // value
Settings::get('keyArray'); // ['arrayKey' => 'arrayValue']
Settings::get('keyNotExists', 'default'); // default

Check value

Determine if setting exists.

Settings::has('key'); // true
Settings::has('keyNotExists'); // false

Forget value

Remove setting from database and cache if enabled

Settings::forget('key');

Flush settings

Remove all setting from database (truncate) and cache if enabled

Settings::truncate();

Set Extra Columns

Sometime you want to specify some criteria for each your setting. This columns will be added to each query. Extra columns always resetted after call of one these methods set, get, has, forget.

Settings::setExtraColumns(['tenant_id' => 1])->set('site_title', 'Awesome Blog');
Settings::setExtraColumns(['tenant_id' => 1])->get('site_title'); // Awesome Blog
Settings::setExtraColumns(['tenant_id' => 2])->get('site_title'); // null

Helpers

Settings Instance

Resolve settings service instance.

settings();

Set value

Set setting value

settings([$key => $value]);

Set setting value with extra columns

settings([$key => $value], null, ['tenant_id' => 1])

Get value

Get setting value

settings('key'); // value

Get setting value with extra columns

settings($key, $default, ['tenant_id' => 1])

Testing


composer install
vendor/bin/phpunit

Inspiration

This package was inspired by these great packages

  • https://github.com/anlutro/laravel-settings
  • https://github.com/edvinaskrucas/settings
  • https://github.com/efriandika/laravel-settings