- Simple key-value storage
- Localization supported.
- Localization using Astrotomic/laravel-translatable Structure
-
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
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
Settings::get('item');
// return null;
Settings::set('item', ['USB' => '8G', 'RAM' => '4G']);
Settings::get('item');
// return array(
// 'USB' => '8G',
// 'RAM' => '4G',
// );
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';
You can extend your custom driver by adding this code in
register()
method of yourAppServiceProvier
$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
{
...
}