© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•15mo ago•
8 replies
nexxai

Error when trying to sort table by MorphTo relationship

I have a table with a model (
Person
Person
) and that model has a
MorphTo
MorphTo
relationship type called
user()
user()
. In generating the table, I'm trying to do the following (some fields removed for the example but they do not matter):
        return $table
            ->columns([
                TextColumn::make('user.name')
                    ->label('Name')
                    ->searchable()
                    ->sortable(),
            ])
            ->defaultSort('name', 'asc')
        return $table
            ->columns([
                TextColumn::make('user.name')
                    ->label('Name')
                    ->searchable()
                    ->sortable(),
            ])
            ->defaultSort('name', 'asc')

but when I try to view the table, I get this:
Illuminate \ Database \ QueryException
PHP 8.3.14
11.33.2
SQLSTATE[HY000]: General error: 1 no such column: laravel_reserved_0.
select * from "people" where "people"."deleted_at" is null order by (select "name" from "people" as "laravel_reserved_0" where "laravel_reserved_0"."" = "people"."user_id" and "laravel_reserved_0"."deleted_at" is null) asc limit 10 offset 0
Illuminate \ Database \ QueryException
PHP 8.3.14
11.33.2
SQLSTATE[HY000]: General error: 1 no such column: laravel_reserved_0.
select * from "people" where "people"."deleted_at" is null order by (select "name" from "people" as "laravel_reserved_0" where "laravel_reserved_0"."" = "people"."user_id" and "laravel_reserved_0"."deleted_at" is null) asc limit 10 offset 0

The
where "laravel_reserved_0".""
where "laravel_reserved_0".""
looks suspicious to me (why is the column name blank?), and I suspect it has something to do with the MorphTo relationship, but I'm not clear where to even continue looking and troubleshooting.

I have confirmed:
- Without the
defaultSort()
defaultSort()
, the table displays the correct
user.name
user.name
value so it's something to do with this call
- Every
Person
Person
has a valid
user_id
user_id
and
user_type
user_type
entry filled in
- Every referenced
user_id
user_id
has a valid (non-null)
name
name
value

I'm also having what I think might be a similar issue with the related form for this table; if I try to add
live()
live()
to the email address field which lives on the same
user
user
relationship, it doesn't actually fire. I can see the network call to
/update
/update
happening in the Dev Console, but there's no data in the
components.0.effects.returns
components.0.effects.returns
array which I assume is where any validation errors would otherwise appear?

Is anyone able to give me a hand?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to sort table by relationship?
FilamentFFilament / ❓┊help
15mo ago
Table relationship sort error.
FilamentFFilament / ❓┊help
2y ago
morphTo relationship
FilamentFFilament / ❓┊help
3y ago
Sortable - Sort by far relationship
FilamentFFilament / ❓┊help
3y ago