public function products() {
return $this->hasMany(Product::class);
}
public function category() {
if ($this->parent) {
//recursive to get the root category
return $this->parent->category();
}
return $this->belongsTo(Category::class);
}
public function parent() {
return $this->belongsTo(Product::class);
}
\App\Models\Product::find(2)->categoryTables\Columns\TextColumn::make('category.name')