Certainly! The issue here is that you're using a relative path as the file URL, so Filament is treating it as relative to the current page (which is at /contracts/55), resulting in a link like /contracts/contract_pdfs/....
Instead, you should generate an absolute URL to your file. The best practice is to use Laravel's Storage::url() method, which will produce a URL relative to your public disk and will honor your storage:link configuration.
Here’s how you can fix your code:
use Illuminate\Support\Facades\Storage;
// ...
TextEntry::make('contract_pdf')
->url(fn ($record) => $record->contract_pdf
? Storage::disk('public')->url($record->contract_pdf)
: null)
->openUrlInNewTab()
->inlineLabel(),
Explanation:
Storage::disk('public')->url($record->contract_pdf)will generate a URL like/storage/contract_pdfs/filename.pdf, which is correct if you’re storing in thepublicdisk and used the default storage symlink setup.- The check for
? $record->contract_pdf : nullensures you don't get a URL if there's no file.
Bonus: If, for any reason, you want to display just the file name (not the path), you can use:
TextEntry::make('contract_pdf')
->label('Contract PDF')
->url(fn ($record) => $record->contract_pdf
? Storage::disk('public')->url($record->contract_pdf)
: null)
->display(fn ($record) => basename($record->contract_pdf))
->openUrlInNewTab()
->inlineLabel(),
Summary:
Always use Storage::url() to generate file URLs for files managed by Laravel's storage system. This guarantees you get the right, absolute URL every time.
Let me know if you have further questions!