Skip to content

bavix/laravel-settings

Repository files navigation

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status Mutation testing badge

Package Rank Latest Stable Version Latest Unstable Version License composer.lock

laravel-settings - Keep user settings easy.

  • Vendor: bavix
  • Package: laravel-settings
  • Version: Latest Stable 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

Usage

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

Supported by JetBrains