1. Go to this page and download the library: Download padosoft/laravel-settings library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
padosoft / laravel-settings example snippets
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
SettingsManager::get('foo', 'default value');
SettingsManager::get('foo', 'default value',false,true); //Get cast value without validation
SettingsManager::get('foo', 'default value',false,false); //Get raw value
SettingsManager::get('foo', 'default value',true,false); //Get validated value without cast
SettingsManager::set('set', 'value');//valid for current session
SettingsManager::set('set', 'value','validationRule');//with validation rule valid for current session
SettingsManager::store();//persist settings value on db
SettingsManager::setAndStore('set', 'value','validationRule');//persisted on database
// Get the store instance
settings();
// Get values
settings('foo');
settings('foo', 'default value',true,false);//Get cast value without validation
settingsRaw('foo', 'default value');//Get raw value
settingsAsString('foo', 'default value');//Get value as a String Validated
settings('foo', 'default value',false,true);//Get raw value
settings('foo', 'default value',false,false);//Get validated value without cast
settings('foo', 'default value',);
settings()->get('foo');
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
class PopulateSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (config('padosoft-settings.enabled',false)) {
DB::table('settings')->insert([
//LOGIN
['key'=>'login.remember_me', 'value'=>'1','descr'=>'Enable/Disable remeber me feature','config_override'=>'padosoft-users.login.remember-me','validation_rules'=>'boolean','editable'=>1,'load_on_startup'=>0],
['key'=>'login.login_reset_token_lifetime', 'value'=>'30','descr'=>'Number of minutes reset token lasts','config_override'=>'auth.expire','validation_rules'=>'numeric','editable'=>1,'load_on_startup'=>0],
]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
/*
|--------------------------------------------------------------------------
| Larvel Settings Manager
|--------------------------------------------------------------------------
|
| This option controls if the settings manager is enabled.
| This option should not be is overwritten here but using settings db table
|
|
|
|
*/
'enabled' => true,
'encrypted_keys' => [],
'cast' => [
//Example new cast and validation
//class = class for cast
//method = method for cast
//validate = rule for validation
'boolean' => ['class' => \Padosoft\Laravel\Settings\CastSettings::class, 'method' => 'boolean', 'validate' => 'boolean'],
'listPipe' => ['class' => \App\Casts\ListPipeCast::class, 'validate' => 'regex:/(^[0-9|]+$)|(^.{0}$)/'],
'booleanString' => ['class' => \App\Casts\BooleanString::class,'validate' => 'regex:/^(true|false)/'],
'booleanInt' => ['class' => \App\Casts\BooleanInt::class,'validate' => 'regex:/^(0|1)/'],
],
public function subscribe(Dispatcher $events): void
{
$events->listen(\Padosoft\Laravel\Settings\Events\SettingCreated::class, [SettingsEventSubscriber::class, 'handleSettingCreated']);
$events->listen(\Padosoft\Laravel\Settings\Events\SettingUpdated::class, [SettingsEventSubscriber::class, 'handleSettingUpdated']);
$events->listen(\Padosoft\Laravel\Settings\Events\SettingDeleted::class, [SettingsEventSubscriber::class, 'handleSettingDeleted']);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.