Laravel Eloquent Self Join Parent Child Relationship
class Product_category extends Model
{
//
protected $table='PRODUCT_CATEGORIES';
public $timestamps = false;
public function getParentCategory() {
return $this->hasOne(self::class, 'id', 'parent_id');
}.
public function getChildCategories(){
return $this->hasMany(self::class, 'parent_id','id');
}
I am able to retrieve all child records of table by making use of getChildeCategories but not able to retrieve Parent of particular category. It always gives me null.