[WIP] A
This commit is contained in:
40
Modules/Internal/Transformers/ClaimRequestShowResource.php
Normal file
40
Modules/Internal/Transformers/ClaimRequestShowResource.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Internal\Transformers;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ClaimRequestShowResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$data = parent::toArray($request);
|
||||
|
||||
// Map Histories to Group by Dates
|
||||
$historiesGroupByDate = $this->histories->mapToGroups(function($history) {
|
||||
return [$history->created_at->format('Y-m-d') => $history];
|
||||
});
|
||||
$data['histories_by_date'] = [];
|
||||
foreach ($historiesGroupByDate as $date => $histories) {
|
||||
$data['histories_by_date'][] = [
|
||||
'date' => $date,
|
||||
'histories' => $histories
|
||||
];
|
||||
}
|
||||
|
||||
// Map Files by type
|
||||
$filesGroupByType = $this->files->mapToGroups(function($file) {
|
||||
return [Str::slug($file->type, '_') => $file];
|
||||
});
|
||||
$data['files_by_type'] = $filesGroupByType;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user