/** * Constructor */ public function __construct($model) { parent::__construct($model); $this->model->setTable('system_settings'); $this->model->jsonable(['value']); $this->model->guard([]); $this->model->timestamps = false; // Option A: (@todo Determine which is faster by benchmark) // $relativePath = strtolower(str_replace('\\', '/', get_class($model))); // $this->configPath = ['modules/' . $relativePath, 'plugins/' . $relativePath]; // Option B: $this->configPath = $this->guessConfigPathFrom($model); /* * Access to model's overrides is unavailable, using events instead */ $this->model->bindEvent('model.afterFetch', [$this, 'afterModelFetch']); $this->model->bindEvent('model.beforeSave', [$this, 'beforeModelSave']); $this->model->bindEvent('model.afterSave', [$this, 'afterModelSave']); $this->model->bindEvent('model.setAttribute', [$this, 'setSettingsValue']); $this->model->bindEvent('model.saveInternal', [$this, 'saveModelInternal']); /* * Parse the config */ $this->recordCode = $this->model->settingsCode; }
/** * Constructor */ public function __construct($model) { parent::__construct($model); $model->addFillable(['country', 'country_id', 'country_code', 'state', 'state_id', 'state_code']); $model->belongsTo['country'] = ['RainLab\\Location\\Models\\Country']; $model->belongsTo['state'] = ['RainLab\\Location\\Models\\State']; }
/** * Constructor */ public function __construct($model = null) { parent::__construct($model); /* * Parse the config */ $this->configPath = $this->guessConfigPathFrom($this); $this->fieldConfig = $this->makeConfig($this->defineFormFields()); if (!$model) { return; } $this->boot($model); }
/** * Constructor */ public function __construct($model) { parent::__construct($model); $this->initTranslatableContext(); $this->model->bindEvent('model.beforeGetAttribute', function ($key) use($model) { if ($this->isTranslatable($key)) { return $this->getTranslateAttribute($key); } }); $this->model->bindEvent('model.beforeSetAttribute', function ($key, $value) use($model) { if ($this->isTranslatable($key)) { return $this->setTranslateAttribute($key, $value); } }); $this->model->bindEvent('model.saveInternal', function ($data, $options) use($model) { $this->syncTranslatableAttributes(); }); }