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:Jump to solution
@Markwowz
See : https://laravel.com/docs/10.x/eloquent-serialization#appending-values-to-json
```php ...
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.
4 Replies
Is that remaining quantity on a related model? Take a look at https://filamentphp.com/docs/3.x/tables/columns/relationships#aggregating-relationships or maybe use accessor (getRemainingAttribute) on the model.
It is not, this is the function on the model:
public function remaining(): int
{
return $this->quantity - $this->bookings()->count();
}
Solution
@Markwowz
See : https://laravel.com/docs/10.x/eloquent-serialization#appending-values-to-json
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.
This is exactly what I needed!
Thank you so much for your help!