Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to define collection & item after resource name #27

Conversation

antonkomarev
Copy link
Contributor

@antonkomarev antonkomarev commented Jul 23, 2017

I've faced a situation where I'm creating fractal response in constructor and filling resources in methods:

public function __construct(Request $request)
{
    $this->response = fractal()
        ->withResourceName('users')
        ->transformWith(new UserTransformer)
        ->parseIncludes($request->input('include'));
}

public function index()
{
    // Some logic

    return $this->response->collection($users)->respond();
}

public function show($id)
{
    // Some logic

    return $this->response->item($user)->respond();
}

Without this change collection & item methods overwriting resourceName variable with null value and the only way to make it work - use data('collection', $users) method instead.

@freekmurze freekmurze merged commit b5c91e7 into spatie:master Jul 24, 2017
@freekmurze
Copy link
Member

Thanks!

@antonkomarev antonkomarev deleted the feature/define-collection-after-resource-key branch July 24, 2017 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants