Skip to content
This repository has been archived by the owner on Sep 15, 2018. It is now read-only.

Persistent, application-wide settings for Laravel 5.

License

Notifications You must be signed in to change notification settings

AlexanderPoellmann/Laravel-Settings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latest Stable Version Total Downloads License

Laravel Settings

Persistent, application-wide settings for Laravel 5.

Attention: This package is a work in progress, please use with care and be sure to report any issues!

Installation

Require the package from your composer.json file

"require": {
	"vendocrat/laravel-settings": "dev-master"
}

and run $ composer update or both in one with $ composer require vendocrat/laravel-settings.

Next register the service provider and (optional) facade to your config/app.php file

'providers' => [
    // Illuminate Providers ...
    // App Providers ...
    vendocrat\Settings\SettingsServiceProvider::class
];
'providers' => [
	// Illuminate Facades ...
    'Setting' => vendocrat\Settings\Facades\Setting::class
];

Configuration

Laravel Settings includes an optional config file. Get started buy publishing it:

$ php artisan vendor:publish --provider="vendocrat\Settings\SettingsServiceProvider" --tag="config"

This will create a config/settings.php file where you can set for example which driver you want to use (JSON file, database, ...).

Migration

Note: You'll only need to complete this step when using the database driver.

If you want to store your settings in your database, you'll have to set 'driver' in your config/settings.php file to 'database' and publish the migration like so:

$ php artisan vendor:publish --provider="vendocrat\Settings\SettingsServiceProvider" --tag="migrations"

Afterwards you'll have to run the artisan migrate command:

$ php artisan migrate

Usage

Get all settings
$settings = \Setting::all();
Check if a setting exists
\Setting::has($key);
Get a setting
$setting = \Setting::get($key);
Add/update a setting
\Setting::set($key, $value);
Delete a setting
\Setting::forget($key);
Delete all settings
\Setting::flush();
Save your updates (set, forget, flush)
\Setting::save();

Example

The following example would store the setting 'bar' with the key 'foo', then update it to 'bars', save it and then die & dump all current settings, which is only one unique 'foo' key-value pair.

\Setting::set('foo', 'bar');
\Setting::set('foo', 'bars');

\Setting::save();

dd(\Setting::all());

Results in

array [
  "foo" => "bars"
]

My Edits

  • restructured folders & files
  • uses Eloquent models for database driver with soft deleting
  • add interface contract
  • removed middleware

To-Dos

  • add Redis support
  • add option to group settings (e.g. config/user/...)
  • add logic to automatically render input forms in the frontend for settings (like a simple App Settings view or so)

License

Licensed under MIT license.

Author

Handcrafted with love by Alexander Manfred Poellmann for vendocrat in Vienna & Rome.

Based on Laravel Settings by Andreas Lutro.

About

Persistent, application-wide settings for Laravel 5.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages