© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
6 replies
Markwowz

Display TextColumn based on model function

What is the best apporach for displaying a TextColumn in my table that references a function on my model? I currently have a Model called Ticket which has a function called remaining() which returns the remaining quantity of the ticket as an integer.
Solution
@Markwowz

See : https://laravel.com/docs/10.x/eloquent-serialization#appending-values-to-json

php 

protected $appends = ['remaining'];

public function getRemainingAttribute(): int
{
    return $this->quantity - $this->bookings()->count();
}
php 

protected $appends = ['remaining'];

public function getRemainingAttribute(): int
{
    return $this->quantity - $this->bookings()->count();
}


You cant use sortable or searchable on column

@Tim van Heugten correct me if i'm wrong
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Laravel - The PHP Framework For Web Artisans
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

TextColumn searchable function anomaly.
FilamentFFilament / ❓┊help
15mo ago
CheckBoxList, Enums and TextColumn display conundrum
FilamentFFilament / ❓┊help
2y ago
Display Model name on page title
FilamentFFilament / ❓┊help
4mo ago
multiple resources based on same model
FilamentFFilament / ❓┊help
2y ago