rexlabsio / smokescreen-laravel-php

Library for integrating the Smokescreen transformation library with the Laravel framework
MIT License
4 stars 1 forks source link

Transforming items that aren't Models #5

Closed CameronDarragh closed 6 years ago

CameronDarragh commented 6 years ago

The transform method assumes that anything that isn't a Model is a Collection.

This caused a problem when trying to transform a regular object, in this case AdPreview. Our solution was to just use Smokescreen::item, but transform should be able to pick up that this is not a collection and therefore an item.

jodiedunlop commented 6 years ago

Hey @CameronDarragh thanks for the feedback. I've refactored the type inference in master. Should correctly determine that a plain object is treated as an Item.

You can now also explicitly define that your class is either an item or resource by implementing one of the empty interfaces:

class SomeClass implements \RexSoftware\Laravel\Smokescreen\Resources\ItemResource {}
class SomeClass implements \RexSoftware\Laravel\Smokescreen\Resources\CollectionResource {}