Package Data | |
---|---|
Maintainer Username: | bitempest |
Maintainer Contact: | ionut.milica@gmail.com (Milica Ionut) |
Package Create Date: | 2015-08-14 |
Package Last Update: | 2017-06-09 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:19:46 |
Package Statistics | |
---|---|
Total Downloads: | 129 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 3 |
Total Forks: | 3 |
Total Open Issues: | 0 |
Laravel settings it's a composer package made for our projects that allows developers to persist settings into database or json files.
PHP 5.4+ and Laravel 5.* are required.
To get the latest version of Laravel Settings run the following command:
composer require ionutmilica/laravel-settings
Once Laravel Settings is installed, you need to register the service provider. Open up config/app.php
and add the following to the providers
key.
'IonutMilica\LaravelSettings\SettingsServiceProvider'
You can register the Settings facade in the aliases
key of your config/app.php
file if you like.
'Settings' => 'IonutMilica\LaravelSettings\Facade'
If you want to have persistent settings, you will need to add a new middleware in app/Http/Kernel.php
to the middleware
key.
'IonutMilica\LaravelSettings\SavableMiddleware',
Laravel settings default driver is set to json. If you want to change it you can execute artisan vendor:publish
command and then modify app/config/settings.php
file.
If you chose database driver you should also migrate the database with php artisan migrate
.
For simple usage we provide a helper that provides all the features you need:
$canRegister = settings('restrictions.register');
if (! $canRegister) {
// do something
}
// Fetching with default value
$canRegister = settings('restrictions.register', false);
// Fetching and save the setting if it does not exist
$canRegister = settings('restrictions.register, false, true);
settings()->set('my-setting', 'some-value');
if (settings()->has('my-setting')) {
// do something
}
settings()->forgot('my-setting');
settings()->set('the-answer', 42);
settings()->save();
You can also inject the settings instance into your laravel controller:
use IonutMilica\LaravelSettings\SettingsContract;
class RegistrationController extends Controller {
public function register(Request $request, SettingsContract $settings)
{
if ($settings->get('restrictions.registration')) {
return redirect()->back();
}
// Do something
}
}
More examples will follow!