serializer = $serializer; } public function transform(Paymentable $paymentable) { $entity_key = 'invoice_id'; if($paymentable->paymentable_type == Credit::class) $entity_key = 'credit_id'; return [ 'id' => $this->encodePrimaryKey($paymentable->id), $entity_key => $this->encodePrimaryKey($paymentable->paymentable_id), 'amount' => (float)$paymentable->amount, 'refunded' => (float)$paymentable->refunded, 'created_at' => (int) $paymentable->created_at, 'updated_at' => (int) $paymentable->updated_at, ]; } }