PHP code example of ralphmorris / exporter

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

    

ralphmorris / exporter example snippets


use RalphMorris\Exporter\Exporter;

public function export()
{
    $users = User::get();

    $exporter = new Exporter;

    return $exporter->exportToCsv($users);
}

return $exporter->exportToCsv($users, 'my-file-name.csv');



namespace App;

use Illuminate\Database\Eloquent\Model;
use RalphMorris\Exporter\ExportableColumnsTrait;

class User extends Model
{
    use ExportableColumnsTrait;

	/**
	 * The columns that are exportable to CSV
	 * 
	 * @var array
	 */
    protected $exportableColumns = [
        'name',
        'email',
    ];

public function export()
{
    $users = User::exportableColumns()->get();

    $exporter = new Exporter;

    return $exporter->exportToCsv($users);
}