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/ */
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,
];