PHP code example of backpack / download-operation

1. Go to this page and download the library: Download backpack/download-operation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

backpack / download-operation example snippets


    /**
     * Configure what the Download button actually downloads.
     */
    public function setupDownloadOperation()
    {
        // [OPTION 1] - you can manually add your columns:
        CRUD::column('title');
        
        // [OPTION 2] - since you've probably already defined columns in your List or Show operation, you could do:
        $this->setupListOperation(); // or $this->setupShowOperation();
        
        // in addition, in case you want to change settings:
        CRUD::set('download.view', 'user.invoice.download'); // default is: crud::show
        CRUD::set('download.format', 'A3'); // default is: A4
        CRUD::set('download.headers', ['Content-Type' => 'application/pdf']); // default is: ['Content-Type' => 'application/pdf']

        // in case you want to configure browsershot instance. more info on Overriding section.
        CRUD::set('download.browsershot', \App\DownloadInvoice::class); // default is: null
    }

    // in your EntityCrudController.php
    protected function setupDownloadOperation() {
        // ...
        CRUD::set('download.browsershot', \App\DownloadInvoice::class);
    }

    // create the following file in App\DownloadInvoice.php
    namespace App;

    use Spatie\Browsershot\Browsershot;

    class DownloadInvoice
    {
        public function __invoke($data)
        {
            // check spatie docs for more options
            return Browsershot::html(view($data['view'], $data))
                ->noSandbox()
                ->setChromePath('/usr/bin/google-chrome-stable')
                ->format($data['format'])
                ->pdf();
        }
    }

    protected function downloadFile($data)
    {
        return response()->streamDownload(function () use ($data) {
            echo Browsershot::html(view($data['view'], $data))
                ->format($data['format'])
                ->pdf();
        }, $data['filename'], $data['headers']);
    }

use Spatie\Browsershot\Browsershot;

Browsershot::url('https://google.com')->ignoreHttpsErrors()->save('example.pdf');
bash
php artisan vendor:publish --provider="Backpack\DownloadOperation\AddonServiceProvider" --tag=config