Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I try to add fields into DownloadExcel using example - but file is not uploaded, #182

Open
sergeynilov opened this issue Nov 8, 2024 · 2 comments

Comments

@sergeynilov
Copy link

I have installed "maatwebsite/laravel-nova-excel": "^1.3" into Laravel 10 / php 8.2/ nova 4.27 app
and I added DownloadExcel method into actions methods of Users resource.
It works ok, but I also need to add more fields from related Profile table.

I found this
#74
branch and created a class app/Library/DownloadUsersIntoExcel.php :

<?php

namespace App\Library;
use App\Models\User;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Http\Requests\ActionRequest;
use Maatwebsite\LaravelNovaExcel\Actions\DownloadExcel;

class DownloadUsersIntoExcel extends DownloadExcel
{

    /**
     * @param ActionRequest $request
     * @param Action        $exportable
     *
     * @return array
     */
    public function handle(ActionRequest $request, Action $exportable): array
    {
        $retArray = [];
        $exportable->query = $this->customQuery($request);
        \Log::info(varDump($exportable->query, ' -1 handle $exportable->query::'));
        return $retArray;
    }

    private function customQuery($request)
    {
        \Log::info(' -1 customQuery $exportable->query::');
        return User::all();
    }

}

and use it in app/Nova/User.php class :

    public function actions(NovaRequest $request)
    {
        return [
            new DownloadUsersIntoExcel,
        ];
    }

Runnin the action I see log lines in log file(methods handle and customQuery are called), but is not is_uploaded -
I have no download dialog under my Chrome...

How to fix it ?

@patrickbrouwers
Copy link
Member

You shouldn't overrule the handle method like that, now the entire excel export part is never called

@sergeynilov
Copy link
Author

Please, provide an example, link in which way I can do it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants