PHP code example of juniorzavaleta / mysql-csv
1. Go to this page and download the library: Download juniorzavaleta/mysql-csv 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/ */
juniorzavaleta / mysql-csv example snippets
$generator = new CsvGenerator('complaints');
$generator->setTitles(
'Id',
'Tipo contaminacion',
'Distrito',
'Estado',
'Fecha de registro'
);
$generator->setColumns(
'complaints.id',
'contamination_types.description',
'districts.name',
'complaint_states.description',
'complaints.created_at'
);
$generator->setFilename(storage_path('app/csv/casos_'.date('d_m_Y_H_i_s').'.csv'));
$generator->join('contamination_types', 'complaints.type_contamination_id', 'contamination_types.id')
->join('districts', 'complaints.district_id', 'districts.id')
->join('complaint_states', 'complaints.complaint_state_id', 'complaint_states.id');
if (!$user->is_admin) {
$generator->where('complaints.district_id', session('district_id'))
->whereNot('complaint_state_id', Complaint::INCOMPLETED);
}
$generator->whereIf('complaint_states.description', request('estado'))
->whereIf('districts.name', request('distrito'))
->whereIf('contamination_types.description', request('tipo_contaminacion'))
->orderBy('complaints.id', 'DESC');
$filename = $generator->execute();
return response()->download($filename)->deleteFileAfterSend(true);
[mysqld]
secure-file-priv = ""