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

Laravel Resource Support #24

Merged
merged 7 commits into from
Nov 3, 2019
Merged

Laravel Resource Support #24

merged 7 commits into from
Nov 3, 2019

Conversation

mpyw
Copy link
Member

@mpyw mpyw commented Nov 2, 2019

Resolves #22 (by @trevorgehman)

Use helper traits on Resource and ResourceCollection.

use Illuminate\Http\Resources\Json\JsonResource;
use Lampager\Laravel\LampagerResourceTrait;

class PostResource extends JsonResource
{
    use LampagerResourceTrait;
}
use Illuminate\Http\Resources\Json\ResourceCollection;
use Lampager\Laravel\LampagerResourceCollectionTrait;

class PostResourceCollection extends ResourceCollection
{
    use LampagerResourceCollectionTrait;
}
$posts = App\Post::lampager()
    ->orderByDesc('id')
    ->paginate();

return new PostResourceCollection($posts);
{
  "data": [/* ... */],
  "has_previous": false,
  "previous_cursor": null,
  "has_next": true,
  "next_cursor": {/* ... */}
}

@mpyw mpyw requested a review from chitoku-k November 2, 2019 19:33
@coveralls
Copy link

coveralls commented Nov 2, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 9484a4d on laravel-resource-support into 39fe05b on master.

@lampager lampager deleted a comment from coveralls Nov 2, 2019
@lampager lampager deleted a comment from coveralls Nov 2, 2019
@lampager lampager deleted a comment from coveralls Nov 2, 2019
@lampager lampager deleted a comment from coveralls Nov 2, 2019
@mpyw mpyw self-assigned this Nov 2, 2019
@mpyw mpyw force-pushed the laravel-resource-support branch 2 times, most recently from 4e4151f to 1b7e922 Compare November 3, 2019 07:14
return new PostResourceCollection($posts);
```

```json5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know this technique... quite nice!

Copy link
Member

@chitoku-k chitoku-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most of the lines are just properly inherited from the core components. LGTM.

@mpyw mpyw merged commit a063521 into master Nov 3, 2019
@mpyw mpyw deleted the laravel-resource-support branch November 3, 2019 09:35
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.

Make work with Laravel Resources
3 participants