BETA We're building something new — all help is welcome! Contribute →

File Downloads

Trigger file downloads from component methods.

Download Stored File

Download a file from storage.

public function downloadReport()
{
    // Download from default disk
    return $this->download('reports/monthly.pdf');
}

public function downloadInvoice($id)
{
    $invoice = Invoice::findOrFail($id);

    // Custom filename, headers, and disk
    return $this->download(
        path: $invoice->file_path,
        name: "invoice-{$invoice->number}.pdf",
        headers: ['X-Custom' => 'value'],
        disk: 's3'
    );
}

Download Generated Content

Create and download content on-the-fly without storing it.

public function exportCsv()
{
    $csv = "Name,Email\n";

    foreach ($this->users as $user) {
        $csv .= "{$user->name},{$user->email}\n";
    }

    return $this->downloadContent(
        content: $csv,
        name: 'users.csv',
        headers: ['Content-Type' => 'text/csv']
    );
}

public function exportJson()
{
    $data = json_encode($this->settings, JSON_PRETTY_PRINT);

    return $this->downloadContent(
        $data,
        'settings.json'
    );
}

Template Usage

<button v-click:downloadReport>
    Download Report
</button>

<button v-click:exportCsv>
    Export to CSV
</button>

<!-- With loading state -->
<button v-click:downloadReport :disabled="livue.loading">
    <span v-if="livue.isLoading('downloadReport')">
        Preparing...
    </span>
    <span v-else>Download</span>
</button>

Method Parameters

Method Parameters
download() path, name?, headers?, disk?
downloadContent() content, name, headers?

Security

Downloads use encrypted tokens with expiry. Users can only download files through the methods you explicitly expose. The token includes the component name, method, and timestamp to prevent tampering.