© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
5 replies
Vhelkhana

Column relationships dot syntax not working

Why is students.[column] not working? I am getting this error: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'students.student_no' in 'order clause'
SELECT * FROM
pending_email_student_portals
pending_email_student_portals
ORDER BY
students
students
.
student_no
student_no
ASC limit 10 OFFSET 0"

ListPendingEmailStudentPortal.php:
    public function table(Table $table): Table
    {
        return $table
            ->query(PendingEmailStudentPortal::query())
            ->columns([
                TextColumn::make('students.student_no')
                    ->label('Student Number'),
                TextColumn::make('students.last_name')
                    ->label('Last Name'),
                TextColumn::make('students.first_name')
                    ->label('First Name'),
                TextColumn::make('students.middle_name')
                    ->label('Middle Name'),
                TextColumn::make('students.entry_date')
                    ->label('Entry Date'),
                TextColumn::make('Status')
                    ->default('Pending')
            ])
            ->defaultSort('students.student_no', 'asc');
    }
}
    public function table(Table $table): Table
    {
        return $table
            ->query(PendingEmailStudentPortal::query())
            ->columns([
                TextColumn::make('students.student_no')
                    ->label('Student Number'),
                TextColumn::make('students.last_name')
                    ->label('Last Name'),
                TextColumn::make('students.first_name')
                    ->label('First Name'),
                TextColumn::make('students.middle_name')
                    ->label('Middle Name'),
                TextColumn::make('students.entry_date')
                    ->label('Entry Date'),
                TextColumn::make('Status')
                    ->default('Pending')
            ])
            ->defaultSort('students.student_no', 'asc');
    }
}


Students table:
[first pic]

PendingEmailStudentPortals table:
[second pic]

PendingEmailStudentPortal model:
class PendingEmailStudentPortal extends Model
{
    use HasFactory;

    protected $guarded = [
        'id',
        'created_at',
        'updated_at',
    ];

    public function students(): HasMany
    {
        return $this->hasMany(Student::class);
    }
}
class PendingEmailStudentPortal extends Model
{
    use HasFactory;

    protected $guarded = [
        'id',
        'created_at',
        'updated_at',
    ];

    public function students(): HasMany
    {
        return $this->hasMany(Student::class);
    }
}
image.png
image.png
Solution
Thanks, I changed the relationship to BelongsTo then added ->sortable() to the student_no column.
Jump to solution
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

Column relationships problem
FilamentFFilament / ❓┊help
2y ago
withoutGlobalScope() with Column Relationships
FilamentFFilament / ❓┊help
9mo ago
Select::selectablePlaceholder(false) not working with relationships
FilamentFFilament / ❓┊help
2y ago
Export Column State Not Working
FilamentFFilament / ❓┊help
2y ago