F
Filament12mo ago
Chanda

form-field

I have a column in Loans table called loan_agreement_file_path which stores the path of a file. Now what I want is to show the file link of this file in a table list such that when a user clicks on it he/she can download the file. This is what I have a tried but its not working:
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('loan_agreement_file_path')
->formatStateUsing(function (string $state): string {
return url("<a href=\"" . asset($state) . "\">Loan Agreement Form</a>");
})
->sortable(),

....................................
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('loan_agreement_file_path')
->formatStateUsing(function (string $state): string {
return url("<a href=\"" . asset($state) . "\">Loan Agreement Form</a>");
})
->sortable(),

....................................
Any Ideas?
5 Replies
MyFrend
MyFrend12mo ago
use a suffix in your table so u have the full link there? u have some exampledata of what u want as input and output?
Chanda
ChandaOP12mo ago
@MyFrend Just a normal href tag we know, suppose my file path under loan_agreement_file_path is 'original_document_name.pdf' then in my table list I will put this file name which has been retrieved in the href i.e <a href="original_document_name.pdf" >Form</a> and in the table list only the 'Form' text will appear and when clicked will lead to that download/view of that file.
Lara Zeus
Lara Zeus12mo ago
TextColumn::make('loan_agreement_file_path')
->formatStateUsing(function (string $state): string {
return 'Loan Agreement Form';
})
->formatStateUsing(function (string $state): string {
return $state;
})
TextColumn::make('loan_agreement_file_path')
->formatStateUsing(function (string $state): string {
return 'Loan Agreement Form';
})
->formatStateUsing(function (string $state): string {
return $state;
})
hope this help
Chanda
ChandaOP12mo ago
@Lara Zeus Still not working as expected, its showing the full file path instaed: LOAN_AGREEMENT_FORMS/2023/DOCX/MyWLZ0ng3gWTjalQr205ikyb6BGCjnWvTRQtugPj.docx
Lara Zeus
Lara Zeus12mo ago
sorry I copy past and didnt change the second one is ->url()
->formatStateUsing(function (string $state): string {
return 'Loan Agreement Form';
})
->url(function (string $state): string {
return $state;
})
->formatStateUsing(function (string $state): string {
return 'Loan Agreement Form';
})
->url(function (string $state): string {
return $state;
})
Want results from more Discord servers?
Add your server