© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
Arjen

Table column loses data when sorting by relationship

I have the following relation
Booking
Booking
-> HasMany ->
Dayparts
Dayparts
where
Dayparts
Dayparts
has a field
date
date
. I want to sort courses by the first child in
Dayparts
Dayparts
and while the code for that sorts the items in the table correctly, the data in the sorted column in the table just disappears. When the table is not sorted, the date is showing correctly. Any idea what I'm doing wrong? This is the table column in the
BookingResource
BookingResource
:
Tables\Columns\TextColumn::make('dayparts.0.date')
    ->label('Datum')
    ->date('d-m-Y')
    ->sortable(
        query: fn ($query, $direction) => $query
            ->join('dayparts', function ($join) {
                $join->on('dayparts.booking_id', '=', 'bookings.id')
                    ->on('dayparts.id', DB::raw("(SELECT min(id) FROM dayparts WHERE dayparts.booking_id = bookings.id)"));
            })
            ->orderBy('date', $direction)
    ),
Tables\Columns\TextColumn::make('dayparts.0.date')
    ->label('Datum')
    ->date('d-m-Y')
    ->sortable(
        query: fn ($query, $direction) => $query
            ->join('dayparts', function ($join) {
                $join->on('dayparts.booking_id', '=', 'bookings.id')
                    ->on('dayparts.id', DB::raw("(SELECT min(id) FROM dayparts WHERE dayparts.booking_id = bookings.id)"));
            })
            ->orderBy('date', $direction)
    ),

I tried changing
'dayparts.0.date'
'dayparts.0.date'
to
'date'
'date'
as well, but that changes nothing.
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

relationship sorting in table
FilamentFFilament / ❓┊help
3y ago
Table optional relationship and sorting
FilamentFFilament / ❓┊help
3y ago
Issue with Sorting a Summed Relationship Column in Filament Table
FilamentFFilament / ❓┊help
12mo ago
SQL error on table bulk action when originally sorting by relationship count
FilamentFFilament / ❓┊help
3y ago