Code Monkey home page Code Monkey logo

laravel-model-transformer's Issues

generate Transformer wrong


     * @param  Model  $model
     * @return array
     */
    public function transformModel(Model $model): array
    {
        return [
        ];
    }

:array
Return type declaration is available in PHP 7 only

but composer.json "require" "php" : ">=5.3.0"

I got error on my model transformer

Hello,

I have problem in using the model transformer, on the controller I called it using this line
$appointments = Appointment::where('field', condition)->get(); return Response()->json(['appointments' => AppointmentTransformer::transform( $appointments )], 200); and my model transformer is
`

class AppointmentTransformer extends Themsaid\Transformers\AbstractTransformer{
public function transformModel(Model $item)
    {
        $output = [
           "field_key" => value
        ];

        return $output;
    }

}

and I get below error:
Declaration of AppointmentTransformer::transformModel() should be compatible with Themsaid\Transformers\AbstractTransformer::transformModel(Illuminate\Database\Eloquent\Model $modelOrCollection). Is there any way how can I fixt this? Thanks :)

Is supported with Laravel 5.3?

Hi,

I found your package very simple but yet very useful, I tried to install it on Laravel 5.3 version but it seems it has an error. Is there any version that would support Laravel 5.3?

Thanks,
Noel

Serializer

I know the consumer API is not really the "Laravel way", but wouldn't it be better to work on a Laravel integration of the Symfony Serializer rather than re-inventing the wheel? Actually the serializer offer you a couple more features:

  • It figures out how to serializer/deserialize your objects automatically, so no need for custom serializers. So instead of having a custom Transformer, you would just need to register the serializer instead.
  • If you need a more granular serialization, for example to display only a few properties or not allow the deserialization of some properties (user password), you can always use groups for it

I had a bit of trouble to use for my app to be honest, mainly because Eloquent models are a bit special making them hard to automatically serialize. I eventually got over it by using EloquentSerializer though.

WDYT?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.