Files
pricebuddy/app/Http/Resources/MetaExtractionResource.php
Jeremy d1a8f1d009 feat: product insights tab
Add a Product Insights tab backed by a suite of price-analysis calculators and a
redesigned price history chart.

- Insights calculators: listing-history and daily best-price series builders,
  price stats, percentile, deal score, distribution, drop events, store showdown,
  seasonality, availability timeline, and target tracker
- ProductInsights aggregator service composing the calculators
- Price history chart: best-price and target datasets, best-price line honours the
  unit/retail filter, horizontal scroll on mobile
- Rename the History tab to Insights with consistent heading styling
- Feature and unit test coverage, plus review-feedback fixes
2026-06-18 23:13:14 +10:00

35 lines
1.1 KiB
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property array $resource
*/
class MetaExtractionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$store = data_get($this->resource, 'store');
return [
'title' => data_get($this->resource, 'title'),
'price' => data_get($this->resource, 'price'),
'image' => data_get($this->resource, 'image'),
'description' => data_get($this->resource, 'description'),
'availability' => data_get($this->resource, 'availability'),
/** @var array<string, StoreResource> */
// Empty object (serialises to `{}`, not `null`) keeps the `store` field shape stable
// for API clients even when no store could be resolved or detected.
'store' => $store ? new StoreResource($store) : (object) [],
];
}
}