atannex/share
atannex/share is a Laravel package for adding share functionality to your app. It offers a simple, framework-friendly way to generate and manage shareable links or social sharing actions, integrating cleanly with Laravel conventions.
Start by publishing the package config and frontend assets, then inspect the share definition API and the Blade component/directive used to render a sheet.
composer require vendor/share-sheet
php artisan vendor:publish --tag=share-sheet-config
php artisan vendor:publish --tag=share-sheet-assets
Look first at:
config/share-sheet.php for sheet defaults, route/signing options, and asset loading.->title(), ->url(), ->file()).First use case: share a server-generated document, such as an invoice PDF, from a Laravel route.
use Vendor\ShareSheet\Facades\Share;
$share = Share::make('invoice-'.$invoice->id)
->title('Invoice #'.$invoice->number)
->text('Your invoice is ready.')
->url(route('invoices.show', $invoice))
->file(route('invoices.pdf', $invoice), 'invoice-'.$invoice->number.'.pdf');
<x-share-sheet :share="$share" id="invoice-share">
<button type="button" data-share-files>
Share invoice
</button>
<a href="#invoice-details" data-share-open="invoice-share#invoice-details">
Jump to details
</a>
</x-share-sheet>
As of v1.1.0, data-share-files buttons share the files attached with ->file() and are rendered only where the device supports native file sharing. The sheet also automatically adds a “Share the file” action when the share has files.
Define shares close to the resource, render them in the view. Build the share in a controller, form request, or dedicated presenter rather than in Blade. This keeps file URLs, signed routes, and authorization logic testable.
public function show(Invoice $invoice)
{
$share = Share::make('invoice-'.$invoice->id)
->title('Invoice #'.$invoice->number)
->url(route('invoices.show', $invoice))
->file(route('invoices.pdf', $invoice), 'invoice.pdf');
return view('invoices.show', compact('invoice', 'share'));
}
Use ->file() for generated or protected assets. Point file URLs at signed, temporary, or otherwise authorized routes. Do not expose private storage paths directly. If the package supports multiple calls, attach several files only when the target platforms and your fallback UI can handle them.
Treat native file sharing as progressive enhancement. Add data-share-files to a normal button inside the sheet. The package hides it when native file sharing is unavailable, so always provide a visible fallback: a download link, an email action, or the sheet’s built-in “Share the file” button. Do not make the native button the only way to access the file.
Use data-share-open for deep links into long sheets. When a sheet contains multiple sections, give each section a stable id and link to it with data-share-open="sheet-id#section-id". This is useful for emails, notifications, and support flows that should open the sheet at “Shipping”, “Payment”, or “Details” rather than at the top.
<section id="payment">
...
</section>
<a href="{{ route('orders.show', $order) }}#payment"
data-share-open="order-share#payment">
Open payment options
</a>
Integrate with Livewire/Alpine carefully. If the sheet is rendered inside a Livewire component, reinitialize or re-render the package’s JS after DOM updates. Prefer stable wire keys and avoid morphing the sheet container while it is open. If you need custom behavior, listen for the package’s open/share events rather than binding directly to internal selectors.
Keep file generation off the initial page render. Generating PDFs or large exports synchronously in the controller can slow down the page. Use an on-demand route, a queued export, or a temporary signed URL so ->file() only points to the asset.
Test the share contract, not just the markup. Assert that the share contains the expected file URL and filename, that sections render with the expected IDs, and that authorization prevents users from generating another user’s file.
data-share-files where unsupported, but keep a fallback action visible.->file() points to a signed route, ensure the URL is valid for the user’s session and does not expire before the share completes. Avoid URLs that require an authenticated XHR fetch the browser cannot perform during sharing.data-share-open="sheet-id#section-id" only works if the sheet ID and section ID match exactly. Avoid dynamic IDs with spaces or special characters; URL-encode values if they are generated.data-share-files needs a share context. A button with this attribute outside the relevant sheet/share scope will do nothing useful. Keep it inside the sheet component or the element that receives the share definition.data-share-files renders on some devices.navigator.canShare/navigator.share support.data-share-files on your own button and listen for the package’s share lifecycle events to add analytics or custom fallback handling.How can I help you explore Laravel packages today?