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();
}


You cant use sortable or searchable on column

@Tim van Heugten correct me if i'm wrong
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.
Was this page helpful?