One solution could be to use a third-party library like SweetAlert2 to display a modal with the link and a copy button. Here's an example of how to do it:
- Install SweetAlert2 via npm:
npm install sweetalert2
- Import SweetAlert2 in your Nova action file:
import Swal from 'sweetalert2';
- In your action method, show a SweetAlert2 modal with the link and a copy button:
public function handle(ActionFields $fields, Collection $models)
{
$link = 'https://example.com'; // Replace with your link
// Show SweetAlert2 modal
$modal = <<<HTML
<div>
<p>Here's your link:</p>
<input type="text" value="$link" readonly>
</div>
HTML;
Swal.fire({
title: 'Link Generated',
html: $modal,
showCancelButton: true,
confirmButtonText: 'Copy Link',
cancelButtonText: 'Close',
reverseButtons: true,
focusConfirm: false,
preConfirm: () => {
// Copy link to clipboard
const input = Swal.getPopup().querySelector('input');
input.select();
document.execCommand('copy');
}
});
// Return a success message
return Action::message('Link generated successfully.');
}
- When the user clicks the "Copy Link" button, the link will be copied to their clipboard. You can also customize the modal further by adding more buttons or changing the styling.
Note: This solution requires JavaScript to be enabled in the user's browser. If you need a solution that works without JavaScript, you may need to create a custom modal or use a different approach.