2

I am Doting Excel export using Laravel with Vuejs, somehow the Code is returning true value but can not Download Excel file, if I do normal request it will download the file, but in axios request, it will not export the file

I am using php artisan make:export to export file

In App/Export/studentexport.php

public function collection()
{
    return Student_master::all();
}

then in controller i will do a function

public function export()
{
    return Excel::download(new StudentExport, 'users.xlsx');
}

In my Vue file i will write a code that cal call the controller and export the file

axios.get('api/export')
            .then(()=>{
                toast({
                    type: 'success',
                    title: 'Export the Data'
                })
            })
            .catch(()=> {
                toast({
                        type: 'warning',
                        title: 'Can not Export'
                        })
            })

but the result is like that

that will return True, I really don't know how to solve this,plase help me

2

3 Answers 3

3

I think is a little bit late but I had the same problem and I just solved it.

For download a file from vuejs, you shouldn't make the request as an Axios petition (at least not that I know). Instead, you can use a href and download attribute inside your template.

This is an example:

<a
    type="button"
    href="/api/export/entity/"
    download="file.xlsx"
>
    <button
        @click="export()"
        class="btn btn-primary"
    >
    Export
    </button>
</a>

The method helps if you need to do another stuff.

I hope this help you.

Sign up to request clarification or add additional context in comments.

1 Comment

It's Works for me
2

ok I solve the problem, I use Vue-excel-export package that will Export the Excel File

enter link description here

this link can help me to install package and use it

Comments

0

I faced the same issue when I was using Inertia, Laravel, or Vue project. But i found the solution.

 exportData() {
            // Construct the download URL with query parameters
            const query = new URLSearchParams({
                search: this.searchQuery,
                sales_persons: this.searchSalesPerson,
                products: this.searchProduct,
                material_types: this.searchMaterial,
                export: 'true'
            }).toString();

            // Trigger the browser to navigate to the download URL
            window.location.href = this.route('module-certificate.index') + '?' + query;
},

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.