Skip to content

laraeast/laravel-settings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StyleCI Travis Build Status Circleci Build Status Total Downloads Latest Stable Version License

Persistent Settings Manager for Laravel

Installation

  1. Install package

    composer require laraeast/laravel-settings
  2. 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,
  3. Create settings table for database driver

    php 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 your AppServiceProvier

EX :
$this->app['settings.manager']->extend('file', function () {
	return new SettingsFileDriverHandler();
});

Note : your custom driver SettingsFileDriverHandler should implements Laraeast\LaravelSettings\Contracts\SettingsStore contract

<?php

namespace App\LaravelSettings;

use Laraeast\LaravelSettings\Contracts\SettingsStore;

class SettingsFileDriverHandler implements SettingsStore
{
    ...
}