HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/dmstechonline/whatsapp.dmstech.online/app/Http/Resources/CampaignResource.php
<?php

namespace App\Http\Resources;

use App\Models\Contact;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class CampaignResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        $totalContacts = Contact::where('organization_id', $this->organization_id)->whereNull('deleted_at')->count();

        return [
            'id' => $this->id,
            'uuid' => $this->uuid,
            'name' => $this->name,
            'template' => $this->template,
            'status' => $this->status,
            'contacts_count' => $this->contactsCount(),
            'delivery_count' => $this->deliveryCount(),
            'read_count' => $this->readCount(),
            'contact_group_count' => $this->contact_group_id == 0 ? $totalContacts : $this->contactGroupCount(),
            // Add other attributes as needed...
        ];
    }
}