Skip to content

Commit

Permalink
change modelable to settingable
Browse files Browse the repository at this point in the history
  • Loading branch information
MoamenEltouny committed Dec 14, 2022
1 parent 25044c2 commit 9187e89
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Classes/Settings.php
Expand Up @@ -40,7 +40,7 @@ public function __construct(Model $model = null, Collection $data = null)
$this->model = $model;
$this->data = $data;
} else {
$this->data = ModelsSettings::whereNull('modelable_type')->get()->keyBy('name');
$this->data = ModelsSettings::whereNull('settingable_type')->get()->keyBy('name');
}
}

Expand Down Expand Up @@ -113,8 +113,8 @@ public function set(...$values)
$obj->value = $values[1] ?? null;

if ($this->model) {
$obj->modelable_type = get_class($this->model);
$obj->modelable_id = $this->model->getKey();
$obj->settingable_type = get_class($this->model);
$obj->settingable_id = $this->model->getKey();
}

$this->data->put($values[0], $obj);
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/Settingable.php
Expand Up @@ -44,9 +44,9 @@ public static function bootSettingable()
* Get the user settings.
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
private function getSettingsColelction()
private function settingables()
{
return $this->morphMany(Settings::class, 'modelable');
return $this->morphMany(Settings::class, 'settingable');
}

/**
Expand All @@ -58,7 +58,7 @@ public function getSettingsAttribute()
{
if ($this->settings_data) return $this->settings_data;

return $this->settings_data = new ClassesSettings($this, $this->getSettingsColelction()->get()->keyBy('name'));
return $this->settings_data = new ClassesSettings($this, $this->settingables()->get()->keyBy('name'));
}

/**
Expand All @@ -68,6 +68,6 @@ public function getSettingsAttribute()
*/
public function clearSettings()
{
return $this->getSettingsColelction()->delete() > 0;
return $this->settingables()->delete() > 0;
}
}
Expand Up @@ -19,8 +19,8 @@ public function up()
$table->string('name');
$table->text('value')->nullable();

$table->string('modelable_type')->nullable();
$table->string('modelable_id')->nullable();
$table->string('settingable_type')->nullable();
$table->string('settingable_id')->nullable();

$table->timestamps();
});
Expand Down

0 comments on commit 9187e89

Please sign in to comment.