flugg / laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fractal with Laravel's elegancy.
MIT License
862 stars 86 forks source link

Parameters are not passing to the overwritten include method #128

Open wahlmika opened 5 years ago

wahlmika commented 5 years ago

Kinda related to #111 because i am dealing with polymorphic relatioships too. I am trying to override include method inside the transformer and query parameters are not passing in to the function.

This is how i call the responder:

return Responder::success($notifications)->respond(200);

Heres how the relationships are declared:

protected $load = [
    'organisation' => OrganisationTransformer::class,
    'user' => UserTransformer::class,
    'relatedUser' => UserTransformer::class,
    'notificationTemplate' => NotificationTemplateTransformer::class,
    'notificationable' // This is the polymoprhic relationship
];

I have overridden the notificationable include same way as in the documentation, but the parameters are not passed to the function.

public function includeNotificationable(Notification $notification, Collection $params) 
{
    dd($params);
}

$params is always an empty collection

`Collection {#517

items: []

}`

Am i doing something wrong or is this a bug?

flugg commented 5 years ago

Hey @wahlmika, sorry for the late response here - did you find a solution to this?

wahlmika commented 5 years ago

Thanks for the response @flugger. Unfortunately i didn't find a solution for this and i had to restructure the code, so that there were no polymorphic relations.

I would still like to know the answer to this if its possible, since there are projects where i'd like to use polymorphic relations.

flugg commented 5 years ago

I'll find some time to research and see if I can replicate the issue and find a solution :)