1. Go to this page and download the library: Download moirei/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 MOIREI\Settings\AsSettingsCollection;
use MOIREI\Fields\Inputs\Boolean;
...
class User extends Model{
...
protected $casts = [
'settings' => AsSettingsCollection::class,
];
/**
* Get settings configuration (optional)
*
* @return array
*/
public function settingsConfig(): array
{
return [
'notifications.enable' => Boolean::make('Enable notification')->default(false),
];
}
}
$user = new User();
$notificationsEnabled = $user->settings->get('notifications.enable');
// Or provide a prefered default
$notificationsEnabled = $user->settings->get('notifications.enable', true);
class User extends Model{
use HasSettings;
// optional if lower-cased pluralised form of class name matches name in groups
protected $settingsConfig = 'users';
}