© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago
403gtfo

Is sortable() and/or searchable() possible on a HasOneThrough relation?

I don't think I have asked this before...
But it is a hard one.

The setup:
- One Staff can have many positions.
- One Position has one Discipline.
- Positions have an end_date field

The question:
Is it possible to have a HasOneThrough relation work with sortable() on the StaffResource?


Relation:
 public function latestDiscipline(): HasOneThrough
  { {
      return $this->hasOneThrough(Discipline::class, Position::class, 'staff_id', 'id', 'id', 'discipline_id')
        ->where('is_active', true)
        ->orderBy('end_date', 'desc');
    }
  }

  public function getLatestDisciplineNameAttribute()
  {
    $latestDiscipline = $this->latestDiscipline()->first();
    return $latestDiscipline ? $latestDiscipline->name : null;
  }
 public function latestDiscipline(): HasOneThrough
  { {
      return $this->hasOneThrough(Discipline::class, Position::class, 'staff_id', 'id', 'id', 'discipline_id')
        ->where('is_active', true)
        ->orderBy('end_date', 'desc');
    }
  }

  public function getLatestDisciplineNameAttribute()
  {
    $latestDiscipline = $this->latestDiscipline()->first();
    return $latestDiscipline ? $latestDiscipline->name : null;
  }


Text column:
TextColumn::make('latest_discipline_name')
    ->label('Discipline')
    // ->searchable()
    ->sortable()
    ->toggleable(),
TextColumn::make('latest_discipline_name')
    ->label('Discipline')
    // ->searchable()
    ->sortable()
    ->toggleable(),
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Searchable and sortable on polymorph
FilamentFFilament / ❓┊help
3y ago
Sortable relation...
FilamentFFilament / ❓┊help
2y ago
Is it possible to make searchable column on relation?
FilamentFFilament / ❓┊help
2y ago
->relationship() with hasOneThrough() relation doesn't work anymore
FilamentFFilament / ❓┊help
3y ago