Hi guys, i am stuck in functionality of building functionality like self Join, for example i may have categories and nested categories, in categories table i put parent_id column which referes to same table but id column to perform categories hierarchy. I tried using hasOne and belongsTo relationship methods but its showing weird messages. i also tried belongsToMany method with same table with foreignkey,local key but then i am getting table alias error. i would really appriciate your help.
// Category.php
public function children()
{
return $this->hasMany(Category::class, 'parent_id');
}
public function parent()
{
return $this->belongsTo(Category::class, 'parent_id');
}