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

withCollection method gives bad json output. I can't convert it to array. #41

Open
nileshlets opened this issue Jul 28, 2017 · 4 comments

Comments

@nileshlets
Copy link

Steps to reproduce

$this->response->withCollection(
$users,
new UserTransformer
);
$array = json_decode($adminUserList);

Expected behavior

It should return an array

Actual behavior

It shows blank. I tested with json_last_error and showing error 4 which means bad syntax.

Server configuration

Ubuntu

Apache

Mysql

PHP 7.0

Client configuration

Chrome

@emileber
Copy link
Contributor

What's $adminUserList in your example?

@nileshlets
Copy link
Author

nileshlets commented Jul 29, 2017

It is output of below code :
$adminUserList = $this->response->withCollection(
$users,
new UserTransformer
);

@nileshlets
Copy link
Author

Hi I have tried other way to achieve this as below and it is working fine:

$adminUserList = $this->response->withCollection(
$users,
new UserTransformer
);
$userCollection = json_decode(json_encode($adminUserList));
$userarray = $userCollection->original->data;

@maximebeaudoin
Copy link
Member

@nileshlets Do you use this package in laravel ? If so, the method withCollection will return a instance of Illuminate\Contracts\Routing\ResponseFactory. See EllipseSynergie\ApiResponse\Laravel::withArray(). The purpose of this package is to simplify the way we transform and return the data in the response.

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

No branches or pull requests

3 participants