PHP code example of stechstudio / laravel-settings

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

    

stechstudio / laravel-settings example snippets


$user->setSetting('theme', 'dark');
$user->setSetting('notifications', true);
$user->setSetting('limits', ['daily' => 100, 'monthly' => 2000]);

$user->setting('theme');          // "dark"
$user->setting('notifications');  // true  (bool)
$user->setting('limits');         // ['daily' => 100, 'monthly' => 2000]
$user->setting('missing', 'n/a'); // "n/a" (default)

use STS\Settings\Concerns\HasSettings;

class User extends Authenticatable
{
    use HasSettings;
}

// Write — the cast type is auto-detected from the value
$user->setSetting('theme', 'dark');

// Read, with an optional default
$user->setting('theme');             // "dark"
$user->setting('missing', 'default'); // "default"

// Existence
$user->hasSetting('theme');          // true

// Delete
$user->deleteSetting('theme');       // true

// Everything as a name => value map
$user->allSettings();                // ['theme' => 'dark', ...]

// Increment a numeric setting (creates it at $amount if absent)
$user->incrementSetting('login_count');     // +1
$user->incrementSetting('credits', 25);     // +25

use STS\Settings\Models\Setting;

$user->setSetting('zip', '90210', Setting::CAST_STRING);
$user->setting('zip'); // "90210" (stays a string)

$users = User::with('settings')->get();

return [
    // The table that holds settings rows.
    'table' => 'settings',

    // The model representing a single setting. Point this at your own
    // subclass of STS\Settings\Models\Setting to add scopes or behaviour.
    'model' => STS\Settings\Models\Setting::class,
];
bash
php artisan vendor:publish --tag=settings-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=settings-config