Created
July 3, 2017 09:21
-
-
Save renepardon/ec23c8796365ea801e736701807f3879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyClass | |
{ | |
public function export() | |
{ | |
$exportable = $this->prepareData($tags); | |
// ... | |
$excel->sheet('Tags', function ($sheet) use ($exportable) { | |
$sheet->fromGenerator($exportable, null, 'A1', false); | |
}); | |
// ... | |
} | |
/** | |
* This is how it looks like now | |
* | |
* @param array $tags | |
* | |
* @return array | |
*/ | |
protected function prepareArrayData(array $tags): array | |
{ | |
$data = []; | |
foreach ($tags as $tag) { | |
$data[] = [ | |
'ID' => $tag->id, | |
'Tag' => strip_tags($tag->tag), | |
'Status' => strip_tags($tag->status), | |
'Created at' => $tag->created_at, | |
'Updated at' => $tag->updated_at, | |
]; | |
} | |
return $data; | |
} | |
/** | |
* This is how it **SHOULD** look like | |
* | |
* @param array $tags | |
* | |
* @return array | |
*/ | |
protected function prepareData(array $tags): array | |
{ | |
foreach ($tags as $tag) { | |
yield [ | |
'ID' => $tag->id, | |
'Tag' => strip_tags($tag->tag), | |
'Status' => strip_tags($tag->status), | |
'Created at' => $tag->created_at, | |
'Updated at' => $tag->updated_at, | |
]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment