36 lines
1.2 KiB
PHP
36 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Resources\Api\V4;
|
||
|
|
|
||
|
|
use App\Models\BrandStat;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Http\Resources\Json\ResourceCollection as JsonResourceCollection;
|
||
|
|
|
||
|
|
class BrandStatsResource extends JsonResourceCollection
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Transform the resource into an array.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @return array
|
||
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||
|
|
*/
|
||
|
|
public function toArray(Request $request)
|
||
|
|
{
|
||
|
|
//phpcs:enable
|
||
|
|
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,
|
||
|
|
'total_accounts' => $brandStat->total_accounts,
|
||
|
|
'total_opt_in' => $brandStat->total_opt_in
|
||
|
|
];
|
||
|
|
})
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|