TreasuryLaunchResource.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  7. use App\Models\TreasuryLaunch;
  8. class TreasuryLaunchResource extends JsonResource
  9. {
  10. /**
  11. * Transform the resource into an array.
  12. *
  13. * @return array<string, mixed>
  14. */
  15. public function toArray(Request $request): array
  16. {
  17. return [
  18. 'id' => $this->id,
  19. 'unit_id' => $this->unit_id,
  20. 'transaction_type' => $this->transaction_type,
  21. 'from_account_id' => $this->from_account_id,
  22. 'to_account_id' => $this->to_account_id,
  23. // Banco da movimentação (destino na entrada, origem na saída).
  24. 'account_id' => $this->transaction_type === 'entrada' ? $this->to_account_id : $this->from_account_id,
  25. 'description' => $this->description,
  26. 'amount' => (float) $this->amount,
  27. 'launch_date' => $this->launch_date,
  28. 'origin' => $this->origin,
  29. 'is_reconciled' => (bool) $this->is_reconciled,
  30. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  31. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  32. ];
  33. }
  34. /**
  35. * @param \Illuminate\Database\Eloquent\Collection<TreasuryLaunch> $resource
  36. * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<TreasuryLaunchResource>
  37. */
  38. public static function collection($resource): AnonymousResourceCollection
  39. {
  40. return parent::collection($resource);
  41. }
  42. }