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

How to return data with the paginator #38

Closed
joshhornby opened this issue Mar 26, 2014 · 3 comments
Closed

How to return data with the paginator #38

joshhornby opened this issue Mar 26, 2014 · 3 comments

Comments

@joshhornby
Copy link

I am struggling to work out how you would return data when using the paginator.

For example I am doing this

$data = $this->some_repo->callPaginator();
$foo = $data->getCollection();

$resource = new Collection($foo, new FooTransformer);
$resource->setPaginator(new IlluminatePaginatorAdapter($data));

If I was to try and $resource->setPaginator(new IlluminatePaginatorAdapter($data)); I get the following error:

The Response content must be a string or object implementing __toString(), "object" given.

So what is the correct way to return data from a paginator?

Thanks

@philsturgeon
Copy link
Member

This was taken care of over email.

@fishactual
Copy link

Hi Phil, for everyone else (myself included) what is the correct way to do this?

@philsturgeon
Copy link
Member

I just shove this into an abstract repository that the others extend:

/**
 * Retrieve all entities
 *
 * @param array $with
 *
 * @return \Illuminate\Database\Eloquent\Collection
 */
public function getAll(array $with = array())
{
    return $this->make($with)->get();
}

/**
 * Retrieve paginated entities
 *
 * @param array $with
 *
 * @return \Illuminate\Pagination\Paginator
 */
public function getPaginated(array $with = array())
{
    return $this->make($with)->paginate();
}

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