My Blog Posts

Laravel Model Settings

Laravel Model Settings

The package has two properties (one or the other, not both) that you can configure in a specific model (settings in one field or table). First, the settings field is a JSON field:

// Settings field

use Glorand\Model\Settings\Traits\HasSettingsField;

class User extends Model
    use HasSettingsField;

    //define only if you select a dirrerent name from the default
    public $settingsFieldName = 'user_settings';  


And a separate setting table option:

use Glorand\Model\Settings\Traits\HasSettingsTable;

class User extends Model
    use HasSettingsTable;

Here are some basic examples of basic uses in a model:

Get all settings

Get a specific setting
$user->settings()->get('some.setting', 'default value');

$user->settings()->set('some.setting', 'new value');
$user->settings()-update('some.setting', 'new value');


You can learn more about this package, get all the setup instructions, and view the source code at glorand/laravel-model-settings on GitHub.

Share this article

Comments (0)