Laravel Model Settings

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

// Settings fielduse 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 use 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 all the installation instructions and view the source code on GitHub at glorand/laravel-model-settings.

  Quote

KARABAY A, 2019 . Laravel Model Settings,

https://www.karabayyazilim.com/blog/php/framework/laravel/laravel-model-ayarlari-2019-07-14-204412

(Accessed July 14, 2019).


  Share this post

Comments (0)

Comment

Subscribe
Sign up for the email newsletter to be the first to know about my blog posts