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?
Solution:Jump to solution
This works.
->url(fn (PipeSurvey $record): string => $record->batch ? PipeBatchResource::getUrl('view', ['record' => $record->batch]) : ''),
...3 Replies
@harps
I used to do links like that but I've had better luck doing them this way.
Not sure if this solves your exact problem but maybe it helps?
or like this for you
I think this works better too when you have multiple panels as your hard coding to the 'admin' path in the route name would cause issues.
That does seem a neater way although it hasn't resolved my issue.
I need to avoid running the function when the relationship does not exist.
->url(fn (PipeSurvey $record): string => PipeBatchResource::getUrl('view', ['record' => $record->batch])),
Batch doesn't exist on some records it's null 🤔Solution
This works.
->url(fn (PipeSurvey $record): string => $record->batch ? PipeBatchResource::getUrl('view', ['record' => $record->batch]) : ''),