laravel-settings - Keep user settings easy.
- Vendor: bavix
- Package: laravel-settings
- Version:
- PHP Version: 7.2+
- Laravel Version:
5.5
,5.6
,5.7
,5.8
,6.x
,7.x
,8.x
- Composer:
composer require bavix/laravel-settings
Add the HasSettings
, HasSetSettings
, HasGetSettings
trait and Settingable
interface to model.
use Bavix\Settings\Traits\HasSettings;
use Bavix\Settings\Traits\HasSetSettings;
use Bavix\Settings\Traits\HasGetSettings;
use Bavix\Settings\Interfaces\Settingable;
class User extends Model implements Settingable
{
use HasGetSettings, HasSetSettings, HasSettings;
}
Checking user settings.
$user = User::first();
$user->getSetting('notify'); // null
$user->getSettingBool('notify'); // null
$user->getSettingBool('notify', false); // bool(false)
Let's save the settings.
(bool)$user->setSettingBool('notify', false); // bool(true)
$user->getSettingBool('notify', false); // bool(false)
Supported by