Skip to content

Commit

Permalink
Don’t include related images in exported csvs
Browse files Browse the repository at this point in the history
The length of the eager load query they create creates issues for sql server
  • Loading branch information
weotch committed Feb 10, 2018
1 parent d41dd5d commit 27399a9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion classes/Controllers/Traits/Exportable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait Exportable
*/
public function csv()
{
$items = $this->makeIndexQuery()->exporting()->get();
$items = $this->makeCsvQuery()->get();
if ($items->isEmpty()) abort(404);
$csv = $this->makeCsv($items);
return response($csv->getContent())->withHeaders([
Expand All @@ -33,6 +33,19 @@ public function csv()
]);
}

/**
* Make the CSV query, removing eager loading of images because that can
* create a passing query that breaks some databases (like sql server)
*
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function makeCsvQuery()
{
return $this->makeIndexQuery()
->withoutGlobalScopes(['decoy.images'])
->exporting();
}

/**
* Build the CSV object from a collection of models
* https://csv.thephpleague.com/9.0/writer/
Expand Down

0 comments on commit 27399a9

Please sign in to comment.