PHP code example of rennokki / eloquent-settings

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

    

rennokki / eloquent-settings example snippets


use Rennokki\Settings\Traits\HasSettings;

class User extends Model {
    use HasSettings;
    ...
}

$user->newSetting('subscribed.to.newsletter', 1);
$user->newSetting('subscribed.to.newsletter', true);

$user->newSetting('subscribed.to.newsletter', true, 'bool');

$user->updateSetting('subscribed.to.newsletter', false, 'bool');

$user->getSetting('subscribed.to.newsletter'); // does not accept a cast

$user->getSettingValue('subscribed.to.newsletter'); // true, as boolean
$user->getSettingValue('subscribed.to.newsletter', 'int'); // 1, as integer

$user->newSetting('is.cool', true, 'bool');
$user->getSettingValue('is.cool'); // it returns true as boolean

$user->getSettingValue('subscribed.to.weekly.newsletter'); // null

$user->deleteSetting('subscribed.to.newsletter');

$user->deleteSettings();