Laravel Model Settings

Laravel Model Settings

Laravel Model Settings is a package by Lorand Gombos to provide model settings configuration in a database field or a separate database table.

The package ships with two traits—settings in a field or table—that you can configure in a given model (one or the other, not both). 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 settings table option:

use Glorand\Model\Settings\Traits\HasSettingsTable;

class User extends Model
{
    use HasSettingsTable;
}

Here’s some basic usage examples in a model:

// Get all settings
$user->settings()->all();

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

// Add/Update
$user->settings()->apply((array)$settings);
$user->settings()->set('some.setting', 'new value');
$user->settings()->update('some.setting', 'new value');

// Remove
$user->settings()->delete('some.setting');

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


Filed in: News


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Laravel Developer (Full-Stack)
Munich
Volunteer Vision GmbH
Full-Stack Developer
Tampa
Nu Image Medical
Senior Software Developer
Remote (US ONLY)/Kenilworth, NJ
Diversified
Senior Back-end Laravel API Developer - Immediate Contract (Full Time)
Remote
ApproveMe // Document Signing
Web Development Project Manager
Houston, TX
Swyft Filings
Experienced Laravel/VueJS Developer (Freelance)
Remote (preferably in the US)
Prosperly LLC
Senior React / Laravel Developer
Remote
The C.A.S.E. Engineering Group