laraeast / laravel-settings
Persistent key-value storage for Laravel
Installs: 18 450
Dependents: 2
Suggesters: 0
Security: 0
Stars: 10
Watchers: 2
Forks: 5
Open Issues: 0
Type:package
Requires
- laravel/framework: >=5.2
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: >=3.0
This package is auto-updated.
Last update: 2024-10-30 01:59:19 UTC
README
Persistent Settings Manager for Laravel
- Simple key-value storage
- Localization supported.
- Localization using Astrotomic/laravel-translatable Structure
Installation
-
Install package
composer require laraeast/laravel-settings
-
Edit config/app.php (Skip this step if you are using laravel 5.5+)
service provider:
Laraeast\LaravelSettings\Providers\SettingsServiceProvider::class,
class aliases:
'Settings' => Laraeast\LaravelSettings\Facades\Settings::class,
-
Create settings table for
database
driverphp artisan settings:table php artisan migrate
Usage
Settings::get('name', 'Computer'); // get setting value with key 'name' // return 'Computer' if the key does not exists Settings::locale('en')->get('name', 'Computer'); // get setting value with key and language Settings::get('name:en', 'Computer'); // get setting value with key and language Settings::set('name', 'Computer'); // set setting value by key Settings::locale('en')->set('name', 'Computer'); // set setting value by key and language Settings::set('name:en', 'Computer'); // set setting value by key and language Settings::has('name'); // check the key exists, return boolean Settings::locale('en')->has('name'); // check the key exists by language, return boolean Settings::has('name:en'); // check the key exists by language, return boolean Settings::delete('name'); // delete the setting by key Settings::locale('en')->delete('name'); // delete the setting by key and language Settings::delete('name:en'); // delete the setting by key and language
Dealing with array
Settings::get('item'); // return null; Settings::set('item', ['USB' => '8G', 'RAM' => '4G']); Settings::get('item'); // return array( // 'USB' => '8G', // 'RAM' => '4G', // );
Usage
Settings::locale('en')->set('title', 'Example Website'); Settings::locale('en')->get('title'); // return return 'Example Website'; Settings::set('title:ar', 'عنوان الموقع'); Settings::locale('ar')->get('title'); // return return 'عنوان الموقع'; Settings::locale('ar')->has('title') // bool Settings::locale('ar')->delete('title') App::setLocale('en'); Settings::locale()->get('title'); // return return 'Example Website';
Extend Driver
You can extend your custom driver by adding this code in
register()
method of yourAppServiceProvier
EX :
$this->app['settings.manager']->extend('file', function () { return new SettingsFileDriverHandler(); });
Note : your custom driver
SettingsFileDriverHandler
should implementsLaraeast\LaravelSettings\Contracts\SettingsStore
contract
<?php
namespace App\LaravelSettings;
use Laraeast\LaravelSettings\Contracts\SettingsStore;
class SettingsFileDriverHandler implements SettingsStore
{
...
}