vaibhavpandeyvpz/laravel-settings

Small library to implement cache-able settings into Laravel projects.

1.1.3 2022-12-21 17:25 UTC

This package is auto-updated.

Last update: 2024-10-21 21:32:38 UTC


README

Yet another but rather small library to implement cache-able settings into Laravel projects, supports Laravel 5 and above.

Installation

composer require vaibhavpandeyvpz/laravel-settings

Laravel < 5.5

Once the package is installed, open your app/config/app.php configuration file and locate the providers key. Add the following line to the end:

Laravel\Settings\SettingsServiceProvider::class

Next, locate the aliases key and add the following line:

'Settings' => Laravel\Settings\SettingsFacade::class,

You can also publish the default configuration and migration using below command:

$ php artisan vendor:publish

Usage

You can use either of settings helper or Settings facade to access the settings.

# store a value
Settings::put('foo', 'bar');
settings(['foo' => 'bar']);
settings()->put('foo', 'bar');
settings('foo', 'bar');

settings()->put('foo', 'bar', false); // don't update in database yet
settings()->commit(); // save to database when you want

# retrieve a value
Settings::get('foo');
settings()->get('foo');
settings('foo');

# retrieve all values
Settings::all();
settings()->all();

# delete a value
Settings::forget('foo');
settings()->forget('foo');

settings()->forget('foo', false); // don't delete from database yet
settings()->commit(); // delete from database when you want

Caching

The package can also cache stored settings for better performance. To cache the settings, run below command:

$ php artisan settings:cache

To clear cached settings anytime, use below command:

$ php artisan settings:clear

License

See LICENSE file.