diff --git a/src/Traits/ExportsCollection.php b/src/Traits/ExportsCollection.php index a0bf08f..b7fdcc2 100755 --- a/src/Traits/ExportsCollection.php +++ b/src/Traits/ExportsCollection.php @@ -19,19 +19,22 @@ trait ExportsCollection * @param Builder $query * @param $format * - * @throws Exception - * * @return mixed + * @throws Exception */ public function export(Builder $query, $format) { $method = 'to'.strtoupper($format); - if (!method_exists($this, $method)) { - throw new Exception(sprintf('Don\'t know how to export to %s format', $format)); + if (method_exists($this, $method)) { + return call_user_func_array([$this, $method], [$query]); } - return call_user_func_array([$this, $method], [$query]); + if (method_exists($this->module, $method)) { + return call_user_func_array([$this->module, $method], [$query]); + } + + throw new Exception(sprintf('Don\'t know how to export to %s format.', $format)); } /** @@ -113,6 +116,12 @@ public function toCSV(Builder $query) return $this->sendDownloadResponse($file, 'csv', ['Content-Type' => 'text/csv']); } + /** + * @param Builder $query + * @return mixed + * @throws Exception + * @throws \Throwable + */ public function toPDF(Builder $query) { if (!app()->has('dompdf.wrapper')) { @@ -134,8 +143,8 @@ public function toPDF(Builder $query) ])->render(); return $pdf->loadHTML($html) - ->setPaper('a4', 'landscape') - ->download(app('scaffold.module')->url().'.pdf'); + ->setPaper('a4', 'landscape') + ->download(app('scaffold.module')->url().'.pdf'); } /** @@ -274,6 +283,9 @@ protected function exportableColumns(): array ->all(); } + /** + * @return mixed + */ protected function exportableView() { return app('scaffold.template')->layout('exportable'); diff --git a/tests/Collection/MutableTest.php b/tests/Collection/MutableTest.php index c4c53b4..1881034 100755 --- a/tests/Collection/MutableTest.php +++ b/tests/Collection/MutableTest.php @@ -266,7 +266,7 @@ public function it_creates_a_group_of_elements() public function it_joins_two_or_more_elements_into_a_group_using_literal_position() { $this->collection - ->join(['first', 'third'], 'group', 'after:second'); + ->stack(['first', 'third'], 'group', 'after:second'); $this->assertCount(2, $this->collection); @@ -279,7 +279,7 @@ public function it_joins_two_or_more_elements_into_a_group_using_literal_positio public function it_joins_two_or_more_elements_into_a_group() { $this->collection - ->join(['first', 'third'], 'group'); + ->stack(['first', 'third'], 'group'); $this->assertCount(2, $this->collection);