Skip to content

Commit 27399a9

Browse files
committed
Don’t include related images in exported csvs
The length of the eager load query they create creates issues for sql server
1 parent d41dd5d commit 27399a9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

classes/Controllers/Traits/Exportable.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait Exportable
2121
*/
2222
public function csv()
2323
{
24-
$items = $this->makeIndexQuery()->exporting()->get();
24+
$items = $this->makeCsvQuery()->get();
2525
if ($items->isEmpty()) abort(404);
2626
$csv = $this->makeCsv($items);
2727
return response($csv->getContent())->withHeaders([
@@ -33,6 +33,19 @@ public function csv()
3333
]);
3434
}
3535

36+
/**
37+
* Make the CSV query, removing eager loading of images because that can
38+
* create a passing query that breaks some databases (like sql server)
39+
*
40+
* @return \Illuminate\Database\Eloquent\Builder
41+
*/
42+
protected function makeCsvQuery()
43+
{
44+
return $this->makeIndexQuery()
45+
->withoutGlobalScopes(['decoy.images'])
46+
->exporting();
47+
}
48+
3649
/**
3750
* Build the CSV object from a collection of models
3851
* https://csv.thephpleague.com/9.0/writer/

0 commit comments

Comments
 (0)