diff --git a/README.md b/README.md index 6629c31..de40b15 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,9 @@ class Post extends Model This trait allows you to generate a slug from a string. When you create a new model, the slug will be generated automatically. If you change the title, the slug will also be updated. See [bootSluggable()](src/Traits/Sluggable.php#L10) method for more details. +> **Note** +> Field name is `parent_id` by default. You can change it in the config file. + > **Note** > Field names are `slug` and `title` by default. You can change it in the config file. diff --git a/src/Traits/ParentChild.php b/src/Traits/ParentChild.php index 2357a47..0faf272 100644 --- a/src/Traits/ParentChild.php +++ b/src/Traits/ParentChild.php @@ -2,6 +2,7 @@ namespace LaravelReady\ModelSupport\Traits; +use Illuminate\Support\Facades\Config; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -9,12 +10,12 @@ trait ParentChild { public function parent(): BelongsTo { - return $this->belongsTo(self::class, 'parent_id'); + return $this->belongsTo(self::class, Config::get('has_active.parent_id', 'parent_id')); } public function children(): HasMany { - return $this->hasMany(self::class, 'parent_id'); + return $this->hasMany(self::class, Config::get('has_active.parent_id', 'parent_id')); } public function recursiveParent(): mixed