ldc-crm/app/Http/Resources/Api/V2/BrandStatsResource.php

36 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2021-11-05 09:04:24 +01:00
<?php
namespace App\Http\Resources\Api\V2;
use App\Models\BrandStat;
use Illuminate\Http\Request;
2021-11-05 09:04:24 +01:00
use Illuminate\Http\Resources\Json\ResourceCollection as JsonResourceCollection;
class BrandStatsResource extends JsonResourceCollection
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
2021-11-05 09:04:24 +01:00
* @return array
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
2021-11-05 09:04:24 +01:00
*/
public function toArray(Request $request): array
2021-11-05 09:04:24 +01:00
{
//phpcs:enable
2021-11-05 09:04:24 +01:00
return [
'stats' => $this->collection->map(function (BrandStat $brandStat) {
return [
'date' => $brandStat->created_at->isoFormat('YYYY-MM-DD'),
'active' => $brandStat->active,
'inactive' => $brandStat->inactive,
'old_accounts' => $brandStat->old_accounts,
'new_accounts' => $brandStat->new_accounts,
2021-11-05 09:04:24 +01:00
'total_accounts' => $brandStat->total_accounts,
'total_opt_in' => $brandStat->total_opt_in
2021-11-05 09:04:24 +01:00
];
})
];
}
}