© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
anjama

Handling null id in column url to related resource

I'm using urls in my tables to allow quick navigation to the views of related records. Here's an example:

TextColumn::make('bird_id')->sortable()->searchable()
    ->url(fn (Capture $record): string => BirdResource::getUrl('view', ['record' => $record->bird_id]))
TextColumn::make('bird_id')->sortable()->searchable()
    ->url(fn (Capture $record): string => BirdResource::getUrl('view', ['record' => $record->bird_id]))


It generally works great, but in one of my tables the column of related ids has null values. These null values cause errors, so they have to be handled. What would be a good approach to conditionally showing these urls when the values are not null?
Solution
->url(fn (?int $state): string => $state ? static::getUrl('view', ['record' => $state]) : null)
->url(fn (?int $state): string => $state ? static::getUrl('view', ['record' => $state]) : null)

?
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Column with relationship link to related resource
FilamentFFilament / ❓┊help
3y ago
Use another column in the url for ID
FilamentFFilament / ❓┊help
2y ago
searchable in id column
FilamentFFilament / ❓┊help
3y ago
Hide Record id from url on edit resource
FilamentFFilament / ❓┊help
3y ago