Custom Column In Table

I have two models. Estimates & Dockets. Relationships are setup in that an Estimate HasOne Docket. Both estimate and docket tables have a title field. I am working on a custom search/table. I want the docket title to show up instead of the estimate title on the TITLE column only if a docket exists. eg
$docket->exists()) ? $docket->title : $estimate->title
$docket->exists()) ? $docket->title : $estimate->title
But I cannot work out how to get that into a singular column. Any help would be appreciated. Thank you
3 Replies
David | Fortune Validator
ended up with this:
TextColumn::make('customTitle')->label('Title')->state(fn (Estimate $estimate) => $estimate->docket->title ?? $estimate->title),
TextColumn::make('customTitle')->label('Title')->state(fn (Estimate $estimate) => $estimate->docket->title ?? $estimate->title),
but I welcome a better solution if there is one 🙂
DrByte
DrByte6mo ago
Does ->getStateUsing() work? Or even ->formatStateUsing()?
David | Fortune Validator
I’d need to look into those and see how differently it affects things. Thanks