Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugbar conflit #34

Open
jonaswebdev opened this issue May 28, 2019 · 14 comments
Open

debugbar conflit #34

jonaswebdev opened this issue May 28, 2019 · 14 comments

Comments

@jonaswebdev
Copy link

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

When I change my .env to debug=false it's solved :)

@usmanhalalit
Copy link
Owner

@jonaswebdev I'm not sure what the actual issue is, can you please explain?

@projct1
Copy link

projct1 commented Jul 8, 2019

@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

@usmanhalalit
Copy link
Owner

@projct1 I don't get what exactly the error is.

@projct1
Copy link

projct1 commented Jul 9, 2019

@usmanhalalit can u see screenshot? http://skrinshoter.ru/s/080719/gLMDYrtt

@usmanhalalit
Copy link
Owner

@projct1 yes, but I don't understand, I'm not a debugbar user either.

@projct1
Copy link

projct1 commented Jul 9, 2019

@usmanhalalit so, that fix problem named "debugbar conflit" should install debugbar i think)

@jonaswebdev
Copy link
Author

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

@usmanhalalit
Copy link
Owner

Thanks for the explanation @jonaswebdev .

I might need to try debugbar.

@pikanglong
Copy link

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:bugreport.png

My Environment:

  • Windows 10 17134
  • PHP 7.3.4-nts
  • MySQL 8.0.12
  • Apache 2.4.39

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, ...)

@divdax
Copy link

divdax commented Aug 15, 2019

Same problem here. Event i disabled debugbar the CSV contains some javascript code.

@projct1
Copy link

projct1 commented Aug 15, 2019

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');

@gianoneil
Copy link

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);

}

@Thowo91
Copy link

Thowo91 commented Oct 1, 2019

Disable the debugbar work for me but i have to do it with this code in Laravel 5.8
app('debugbar')->disable();

@aarondunphy
Copy link

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();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants