PHP code example of sands / laravel-presenter-excel

1. Go to this page and download the library: Download sands/laravel-presenter-excel 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/ */

    

sands / laravel-presenter-excel example snippets


'providers' => [
     ...
     Sands\Presenter\PresenterServiceProvider::class,
     Sands\Presenter\Excel\ExcelPresenterServiceProvider::class,
     ...
]

public function index()
{
    return $this->present(['users' => User::all()])
        ->setOption('excel.fileName', 'User Reports')
        ->using('blade', 'xlsx', 'csv', 'xls');
}

public function csvData()
{
    return [
        "Sheet 1 Name" => [            
            [row 1 data],
            [row 2 data],
            ...
        ],
        ...
    ];
    
    ... or ...
    
    return [
        "Users" => User::all(),
        "Tasks" => Task::all(),
        ...
    ];
}

public function csvData()
{
    return [
        [row 1 data],
        [row 2 data],
        ...
    ];
    
    ... or ...
    
    return User::all();
}

public function index()
{
    return $this->present()
        ->setOption('data.blade', 'bladeData')
        ->setOption('data.xlsx', 'data')
        ->setOption('excel.fileName', 'User Reports')
        ->setOption('excel.title', 'Exported User Reports')
        ->using('blade', 'xlsx');
}