Open jonaswebdev opened 5 years ago
@jonaswebdev I'm not sure what the actual issue is, can you please explain?
@jonaswebdev Same problem:
$select = [
"c.id as ID звонка",
DB::raw("concat(o.date, ' ', o.time) as 'Дата брони'"),
"c.created_at as Дата звонка",
"b.name as Заведение",
"r.total as Сумма",
"c.comments as Комменты звонка"
];
$result = DB::table('calls as c')
->select($select)
->leftJoin('orders as o', 'o.id', 'c.order_id')
->leftJoin('bars as b', DB::raw('ifnull(o.bar_id, c.bar_id)'), 'b.id')
->leftJoin('revises as r', 'r.order_id', 'o.id')
->where('c.is_utm_match', 0)
->get();
$writer = new Export;
$writer->getWriter()->setDelimiter(';')->addFormatter((new CharsetConverter)->outputEncoding('windows-1251'));
$writer->build($result, ['ID звонка', 'Дата брони', 'Дата звонка', 'Заведение', 'Сумма', 'Комменты звонка'])->download('метки-не-совпали.csv');
Result is http://skrinshoter.ru/s/080719/gLMDYrtt
@projct1 I don't get what exactly the error is.
@usmanhalalit can u see screenshot? http://skrinshoter.ru/s/080719/gLMDYrtt
@projct1 yes, but I don't understand, I'm not a debugbar user either.
@usmanhalalit so, that fix problem named "debugbar conflit" should install debugbar i think)
Hi @usmanhalalit sorry by delay.
So, the issue with debugbar
happen on "non-production" environment, it includes some no wished data into CSV file.
I don't know how I could help you, please guide me if you can, but I agree with @projct1, and you could try to use debugbar
on your development environment and see the issue with own eyes when you export a CSV file.
thanks in advance
Thanks for the explanation @jonaswebdev .
I might need to try debugbar.
I'm not a debugbar user, but I have the same problem. After running the code below:
$users = DB::table('users') -> get();
$csvExporter = new \Laracsv\Export();
$csvExporter->build($users,['id','name','email','password'])->download();
I found two lines of strange JavaScript code at the end of the csv file downloaded.
Here is my screenshot:
My Environment:
By the way, I seem to have encountered some Chinese encoding problems. Is there a function that allows me to customize the export encoding?(utf-8, unicode, ...)
Same problem here. Event i disabled debugbar the CSV contains some javascript code.
I use native way and plugin becomes no need:
$formatter = new CharsetConverter;
$writer = Writer::createFromFileObject(new SplTempFileObject);
$writer->setDelimiter(';')->addFormatter($formatter->outputEncoding('windows-1251'));
$header = ['ID брони', 'Дата брони', 'Дата звонка', 'Заведение', 'Сумма', 'Комменты звонка'];
$select = ['o.id', DB::raw("concat(o.date, ' ', o.time)"), 'c.created_at', 'b.name', 'r.total', 'c.comments'];
$result = DB::table('calls as c')
->select($select)
->leftJoin('orders as o', 'o.id', 'c.order_id')
->leftJoin('bars as b', DB::raw('ifnull(o.bar_id, c.bar_id)'), 'b.id')
->leftJoin('revises as r', 'r.order_id', 'o.id')
->where('c.is_utm_match', 0)
->get();
$writer->insertOne($header);
$writer->insertAll(json_decode(json_encode($result), true));
$writer->output('метки не совпали.csv');
The solution I found was
1) Disable Debugbar on the fly 2) Don't render view after exporting the CSV
if ($export == true) {
// Disable Debugbar temporarily
DebugBar::disable();
// Export CSV
$csv_exporter = new \Laracsv\Export();
$csv_exporter->build($orders, ['order_id', 'customer'])->download('orders.csv');
} else {
// Render the View
return view('orders.index')->with('orders', $orders);
}
Disable the debugbar work for me but i have to do it with this code in Laravel 5.8
app('debugbar')->disable();
Very late to the party here but what worked for me was adding die();
after the download command. Example:
public function index(Export $export, GetAllSeoCheckDocuments $getAllSeoCheckDocuments)
{
$documents = $getAllSeoCheckDocuments->execute();
$latestSeoResults = $documents->map(fn ($document) => $document->latestSeo);
$export->build($latestSeoResults, [
'document_type',
'document_id',
'largest_contentful_paint',
])->download('seo_test_results_' . date('d_m_Y_h_i_s') . '.csv');
die();
}
Hi, I just tested this class and love it congratulations to author and all contributors.
I got an issue locally when I created a CSV the laravel-debugbar info are included, see:![Screenshot 2019-05-27 21 47 18](https://user-images.githubusercontent.com/1163141/58443565-0c05cf80-80c9-11e9-86d8-68c8de3eb722.png)
When I change my
.env
todebug=false
it's solved :)