dealhub/app/Http/Resources/DealResource.php
kusowl 9e61dd9f51 feature(deal-modal): add interaction only in card
- show current user liked and favorite status in the modal
2026-01-22 13:34:02 +05:30

33 lines
985 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\URL;
class DealResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'image' => asset('storage/'.$this->image),
'link' => $this->link !== null ? URL::signedRoute('redirect', $this->id) : null,
'category' => $this->whenLoaded('category'),
'broker' => new UserResource($this->whenLoaded('broker')),
'totalLikes' => $this->total_likes,
'totalRedirection' => $this->total_redirection,
'isLiked' => $this->is_liked,
'isFavorite' => $this->is_favorite,
];
}
}