junaidnasir / globalsettings by junaidnasir

Laravel global settings, set/get global settings for your app
1,514
4
1
Package Data
Maintainer Username: junaidnasir
Maintainer Contact: contact@junaidnasir.com (Junaid Nasir)
Package Create Date: 2016-04-14
Package Last Update: 2018-04-17
Language: PHP
License: MIT
Last Refreshed: 2024-11-14 03:00:05
Package Statistics
Total Downloads: 1,514
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 4
Total Watchers: 1
Total Forks: 3
Total Open Issues: 1

Laravel Global Settings

Global Settings package for laravel, to quickly retrieve and store settings data in DB.

Installation

Begin by installing the package through Composer. Run the following command in your terminal:

composer require junaidnasir/globalsettings

add the package service provider in the providers array in config/app.php:

Junaidnasir\GlobalSettings\GlobalSettingsServiceProvider::class

you may add the facade access in the aliases array:

'GlobalSettings'  => Junaidnasir\GlobalSettings\Facades\GlobalSettings::class

publish the migration and config file:

php artisan vendor:publish"

migrate to create global_settings table

php artisan migrate

Usage

You can use facade accessor to retrieve the package controller. Examples:

GlobalSettings::set('allowUserSignUp',0);
GlobalSettings::set('userPostLimit',10);

// Get registration
if( GlobalSettings::get('allowUserSignUp'))
{
    //show form
}

// Post controller
if (count($user->post) >= GlobalSettings::get('userPostLimit'))
{
    // Can not create post limit reached
}

API

/* Set or update setting
*  $isActive is additional parameter 
*  to quickly disable a setting without
*  having to delete the setting
*/
set($Setting, $Value, $isActive = true);

/* Get Settings
*  return value of setting
*  or default value provided
*/
get($Setting, $default = null);

/* check if setting exists 
* return true if setting exists
* false otherwise
*/
has($Setting);

// Other Methods
update($setting, $value, $isActive);

isActive($setting);
activate($setting);
deactivate($setting);
delete($setting);