Reputation: 65
I'm using Laravel Filament and encountering an issue. I have multiple kits allocated to vendors, and I'm displaying the kit names with slug URLs. How can I copy only the URL without copying any other text?
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Components\Section::make()
->schema([
Components\Split::make([
Components\Grid::make()
->schema([
Components\TextEntry::make('vendor.name'),
Components\TextEntry::make('kit_ids')->label('Kits Name & URL')
->formatStateUsing(function (KitAllocation $kitAllocation) {
$kitIds = $kitAllocation->kit_ids;
$kits = Kit::whereIn('id', $kitIds)->get();
$output = '';
foreach ($kits as $kit) {
$url = env('APP_URL') . ('/' . $kitAllocation->vendor->slug . '/' . $kit->slug);
$output .= "<li>" . $kit->kit_name . "<br>" . ' -> ' . $url . "</li>";
}
return $output;
})->html()
->copyable(function (KitAllocation $kitAllocation) {
$kitIds = $kitAllocation->kit_ids;
$kits = Kit::whereIn('id', $kitIds)->get();
if ($kits->isNotEmpty()) {
$kit = $kits->first();
return env('APP_URL') . ('/' . $kitAllocation->vendor->slug . '/' . $kit->slug);
}
return '';
}),
]),
])->from('lg'),
]),
]);
}
I want a data display like this "**Welcome T-shirt & Bag Pack Kits -> http://127.0.0.1:8000/olio-global-adtech/welcome-t-shirt-bag-pack-kits**" and copy only url on particular click text.
How to Copy only url in filament in multiple kits with url.
Any One help me on this.
Upvotes: 0
Views: 636
Reputation: 182
To achieve this, you can use the copyableState()
method to customize the text that is copied to the clipboard. See code below.
...
->html()
->copyable()
->copyableState(
function (KitAllocation $record) {
$kitAllocation = $record;
$kitIds = $kitAllocation->kit_ids;
$kits = Kit::whereIn('id', $kitIds)->get();
if ($kits->isNotEmpty()) {
$kit = $kits->first();
return env('APP_URL') . ('/' . $kitAllocation->vendor->slug . '/' . $kit->slug);
}
return '';
}),
...
Upvotes: 1