PHP code example of am2studio / laravel-exporter

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

    

am2studio / laravel-exporter example snippets


/**
 * Class UserController
 * @package App\Http\Controllers\Backend\Admin
 */
class UserController extends Controller
{
    use \AM2Studio\Laravel\Exporter\Exporter;

/**
 * @return mixed
 */
public function csv()
{
    $users = (new User)->paginate(10);
    return $this->exportOneSheet(
        $users,
        ['first_name' => 'First name', 'last_name' => 'Last Name', 'gender' => 'Gender'],
        'Users', 'users', 'xls', 'Creator', 'Company'
    );
}

First parameter in  \Illuminate\Pagination\LengthAwarePaginator
Second parameter is array with attribute name in db and title in export
Rest parameters are
    title for document
    filename for document
    format for document (xsl,pdf etc.)
    document creator
    document company