<?php
namespace App\Http\Resources;
use App\Models\Currency; use App\Services\MoneyMath; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource;
class MoneyResource extends JsonResource { public function __construct(private int $minor,private string $currency){parent::__construct(null);} public function toArray(Request $request):array{$d=(int)\Illuminate\Support\Facades\Cache::rememberForever('currency.decimals.'.$this->currency,fn()=>Currency::whereKey($this->currency)->value('decimals'));return app(MoneyMath::class)->format($this->minor,$this->currency,$d);} }
