spatie/fractalistic

Using `withResourceName` makes fractal include parameters not working

darkons opened this issue · 2 comments

Example:

$fractal = Fractal::create($users, new UserTransformer())->withResourceName('users');
$fractal->parseIncludes(['posts'])->toArray();

In League\Fractal\TransformerAbstract at callIncludeMethod method we get the following result:

// this line will get 'users.posts' as identifier
$scopeIdentifier = $scope->getIdentifier($includeName);

// this line will try to find include params for 'users.posts' identifier instead 'posts'
$params = $scope->getManager()->getIncludeParams($scopeIdentifier);

But League\Fractal\Scope object is being built like this:

League\Fractal\Scope Object
(
    [availableIncludes:protected] => Array
        (
            [0] => posts
        )
    [scopeIdentifier:protected] => users
    [manager:protected] => League\Fractal\Manager Object
        (
            [requestedIncludes:protected] => Array
                (
                    [0] => posts
                )
            [includeParams:protected] => Array
                (
                    [posts] => Array
                        (
                            [limit] => Array
                                (
                                    [0] => 5,
                                    [1] => 1,
                                )
                        )
                )

As you can see League\Fractal\Manager will not find the posts include params because getIncludeParams method will look for users.posts key instead.

Feel free to PR a fix for this!

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.