Export data in database to various file format . Currently xls,json and csv file formats are supported
use YS\Export\Csv;
use App\User;
public function exportUsers()
{
$csv = new Csv( User::select('*'));
return $csv->response();
}
use YS\Export\Csv;
use App\User;
public function exportUsers()
{
$csv = new Csv( DB::table('users')->select('name','email'));
return $csv->response();
}
use YS\Export\Csv;
use App\User;
public function exportUsers()
{
$query = User::join('companies', 'companies.id','users.company_id')->select('users.name','users.email','companies.name as company');
$csv = new Csv( $query );
return $csv->response();
}
use YS\Export\Json;
use App\User;
public function exportUsers()
{
$json = new Json( DB::table('users')->select('name','email'));
return $json->response();
}
use YS\Export\Xls;
use App\User;
public function exportUsers()
{
$xls = new Xls( DB::table('users')->select('name','email'));
return $xls->response();
}
use YS\Export\ArrayToXls;
use App\User;
/**
* $data array of records to be exported
* eg, $data = [
['name' => 'user', 'email' => '[email protected]','contact' => 123456789],
['name' => 'user1', 'email' => '[email protected]', 'contact' => 123456789]
]
* bool $export with default value as true indicate weather to export data or not
* string $fileName name of the file to be exported
* array $headers with default value as [] if values provided with export only provided columns
* eg, headers = ['name','email'] will export only name and email not contact
*/
public function exportUsers()
{
$xls = new ArrayToXls($data,$export,$fileName,$headers); // will export only name and email
return $xls->response();
}
You can provide column names inside select statement in order to export only selected columns from database.Optionally you can also define column names inside ys-export config file which you do not want to export in file like id,password etc...
To do this just run php artisan vendor:publish and select ys-export:config group