Giter VIP home page Giter VIP logo

Comments (13)

jbardnz avatar jbardnz commented on June 19, 2024 8

@JeffBeltran I did manage to find a workaround that works quite well. I made a custom action with the following code:

class ExportExcel extends ExportToExcel implements WithHeadings
{
    use InteractsWithQueue;

    public function handle(ActionRequest $request, Action $exportable): array
    {

        $resource = $request->resource();

        $filename = '/tmp/' .  $resource::uriKey() . '-' . now()->format('Y-m-d') . '.xlsx';

        $response = Excel::store(
            $exportable,
            $filename,
            $this->getDisk(),
            $this->getWriterType()
        );


        return Action::download(
            Storage::disk($this->getDisk())->url($filename),
            $this->getFilename()
        );
    }


    public function fields()
    {
        return [];
    }
}

This will upload the file to the tmp folder on S3 (so it is removed every 24 hours). Just change the folder location if you don't want it to be deleted. Then on the Nova resource, you can add the action like so:

 (new ExportExcel())->withDisk('my-s3-disk')

from laravel-nova-excel.

jbardnz avatar jbardnz commented on June 19, 2024 1

I'm having the same issue on Laravel Vapor as there is no local filesystem. Is there a way to use the remote_disk to temporarily store the file instead of the local disk?

from laravel-nova-excel.

GlennM avatar GlennM commented on June 19, 2024

Hi Bobby,

The multi-server setup should work for the Laravel Excel Nova package as well.
Please refer to the Laravel Excel documentation about multi-server setup to see how to set things up.

from laravel-nova-excel.

bobbybouwmann avatar bobbybouwmann commented on June 19, 2024

That is perfect! Thanks for sharing that part in the documentation! I have everything up and running now ;)

from laravel-nova-excel.

bobbybouwmann avatar bobbybouwmann commented on June 19, 2024

Sorry I had to reopen this issue again! So I thought I had this working locally, but on my acceptance environment it's still failing. The S3 setup is only working whenever you use queues. But in my case I want to use it without queues as well. Is there a possibility for this?

Updating the local_path doesn't work for me at this point, since we have multiple machines and we don't know where the container is running. Sharing a path isn't going to work as well!

I can make a PR for always being able to use S3, but not sure if you want something like this.

from laravel-nova-excel.

patrickbrouwers avatar patrickbrouwers commented on June 19, 2024

Perhaps we could store the "download" file on the temporary disk. In your case that would go to S3. The api to the ExcelController then downloads it via the temporary disk instead of just calling the full path that is passed. (Sounds a lot better anyway actually haha :) )

Feel free to PR it! Thanks!

from laravel-nova-excel.

bobbybouwmann avatar bobbybouwmann commented on June 19, 2024

I'm not sure how to handle this since the package always sends back the url of the download to the frontend. How would I save the file to own storage and send that url back from the action in Nova?

I will look into making a PR for everyone to use a different local path, queue or not

from laravel-nova-excel.

patrickbrouwers avatar patrickbrouwers commented on June 19, 2024

Instead of sending back the url of the download, send back the path and disk where it's stored. Then in the controller call do the actual download based on those 2 instead of the given full path.

from laravel-nova-excel.

bobbybouwmann avatar bobbybouwmann commented on June 19, 2024

So that basically means overriding the controllers from the laravel-excel-nova package right? It seems to be the only solution at this point.

I also looked in being always able to store temp files on another disk, but that needs some more work in the core laravel-excel package. Looked simpel at first sight hehe!

from laravel-nova-excel.

GlennM avatar GlennM commented on June 19, 2024

How about using a custom action and using ExportToExcel for storing it to a disk of your choice? See Full control

from laravel-nova-excel.

JeffBeltran avatar JeffBeltran commented on June 19, 2024

@jbardnz if you find a solution would you ping me please, same issue

from laravel-nova-excel.

JeffBeltran avatar JeffBeltran commented on June 19, 2024

wow thanks man, my brain is dead so i'll save this for the morning. thanks in advance :D

from laravel-nova-excel.

argia-andreas avatar argia-andreas commented on June 19, 2024

@jbardnz Thank you!
Saved me loads of time! Worked like a charm with Vapor.
I had to remove the leading / in /tmp/. But might be because of my .env file.

from laravel-nova-excel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.