Skip to content

Exporting data as Excel #261

@fbramato

Description

@fbramato

Hi,

i would use the same query builder syntax to export data as Excel.

For example, calling:

User.
    .where(toRaw(filters.value))
    .orderBy((descending ? '-' : '') + sortBy)
    .export('users.xlsx');

would call /users/export with the same querystring parameters of get() method and then use a snippet similar to

axios.get(url, { responseType: 'blob' })
      .then(response => {
        const blob = new Blob([response.data], { type: 'application/pdf' })
        const link = document.createElement('a')
        link.href = URL.createObjectURL(blob)
        link.download = label
        link.click()
        URL.revokeObjectURL(link.href)

or https://www.npmjs.com/package/file-saver

I'm using https://docs.laravel-excel.com/3.1/exports/ and would be incredibly helpful replicate the same get() behaviour exporting the Excel from

public function export()
    {
        $data = QueryBuilder::for(User::class)
            ->allowedFilters(['soggetto', 'soggetto.nominativo', 'login', 'tipo_utente', 'roles.id'])
            ->allowedIncludes(['soggetto'])
            ->with('soggetto')
            ->get();

        return Excel::download(new UsersExport($data), 'users.xlsx');
    }

Maybe is already possible with some hack :)

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions