PHP code example of smartisan / laravel-settings

1. Go to this page and download the library: Download smartisan/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/ */

    

smartisan / laravel-settings example snippets


Settings::set('key', 'value');

Settings::set([
    'k1' => Carbon::now(),
    'k2' => [
        'k3' => $user,
        'k4' => [
            'k5' => $model
        ],  
    ]
]);

Settings::group('name')->set('key', 'value');

Settings::group('name')->set([
    'k1' => 'v1',
    'k2' => 'v2',
]);

Settings::for($model)->set('key', 'value');

Settings::for($model)->set([
    'k1' => 'v1',
    'k2' => 'v2',
]);

Settings::for($model)->group('name')->set('key', 'value');

Settings::get('k1', 'default');

Settings::get(['k1', 'k2', 'k3'], 'default');

Settings::all();

Settings::for($model)->all();

Settings::for($model)->group('name')->all();

Settings::except('k1', 'k2')->for($model)->group('name')->all();

Settings::except('k1')->for($model)->group('name')->all();

Settings::forget('key');

Settings::for($model)->group('name')->forget('key');

Settings::exist('key');

Settings::for($model)->exist('key');

Settings::for($model)->group('name')->exist('key');

settings()->set('key', 'value');
...

use Smartisan\Settings\HasSettings;

class User extends Model
{
    use HasSettings;    
}

$user->settings()->set('k1', 'v1');
...

use Smartisan\Settings\Contracts\Repository;

class FileRepository implements Repository 
{
    public function get($key,$default = null) {
        //
    }
    
    public function set($key,$value = null) {
        //
    }
    
    public function forget($key) {
        //
    }
    
    public function all() {
        //
    }
}

    'repositories' => [
        ...
        
        'file' => [
            ...
        ]
    ],

use Smartisan\Settings\Contracts\Castable;

class CustomCast implements Castable
{
    public function set($payload) {
        //
    }
    
    public function get($payload) {
        //
    }
}

'casts' => [
    ...
    CustomDataType::class => CustomCast::class
]

'casts' => [
    ...
    CustomDataType::class => new CustomCast('param')
]

'cache' => [
    'enabled' => env('SETTINGS_CACHE_ENABLED', false),
    'store' => null,
    'prefix' => null,
],
bash
php artisan vendor:publish --provider="Smartisan\Settings\SettingsServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Smartisan\Settings\SettingsServiceProvider" --tag="migrations"
bash
php artisan migrate