3 Similar Columns (Slug or ID)

I need 3 similar columns on one table. I'm using nested set, but it really just two relationships on the same model.
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}

public function root(): HasOne
{
return $this->hasOne(self::class, 'root_parent_id');
}
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}

public function root(): HasOne
{
return $this->hasOne(self::class, 'root_parent_id');
}
Tables\Columns\TextColumn::make('slug')
->label('Series')
->sortable()
->toggleable()
->wrap()
->searchable(isIndividual: true),
Tables\Columns\TextColumn::make('parent.slug')
->label('Parent')
->sortable()
->toggleable()
->searchable(isIndividual: true),
Tables\Columns\TextColumn::make('root.slug')
->label('Root Parent')
->sortable()
->toggleable()
->searchable(isIndividual: true),
Tables\Columns\TextColumn::make('slug')
->label('Series')
->sortable()
->toggleable()
->wrap()
->searchable(isIndividual: true),
Tables\Columns\TextColumn::make('parent.slug')
->label('Parent')
->sortable()
->toggleable()
->searchable(isIndividual: true),
Tables\Columns\TextColumn::make('root.slug')
->label('Root Parent')
->sortable()
->toggleable()
->searchable(isIndividual: true),
In the above example the first two instances of slug work, but the 3rd doesn't. If I change those to pull the id via relationship it doesn't work either. How can I overcome this? What's going on here in the background?
1 Reply
Mack H
Mack HOP2y ago
The picture above shows the id for root_parent simply cause I called root_parent_id off the row after discovering root.slug wouldn't work. I solved this by changing the HasOne to BelongsTo on the Series Model.
Want results from more Discord servers?
Add your server