url error on relationship
I have an infolist that renders a piece of text from a relationship and it also links to that entity in the relationship.
The problem is that I'm getting an error on the url function when the relationship does not exist. What's the best way to deal with this situation?
The problem is that I'm getting an error on the url function when the relationship does not exist. What's the best way to deal with this situation?
Solution
This works.
->url(fn (PipeSurvey $record): string => $record->batch ? PipeBatchResource::getUrl('view', ['record' => $record->batch]) : ''),