Package Data | |
---|---|
Maintainer Username: | TahiriAbdou |
Maintainer Contact: | ionut.milica@gmail.com (Milica Ionut) |
Package Create Date: | 2016-09-16 |
Package Last Update: | 2021-03-15 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-26 15:07:17 |
Package Statistics | |
---|---|
Total Downloads: | 32 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 1 |
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!