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

[8.x] Added 'pipeInto' method to EnumeratesValues trait #34600

Merged
merged 2 commits into from
Sep 30, 2020
Merged

[8.x] Added 'pipeInto' method to EnumeratesValues trait #34600

merged 2 commits into from
Sep 30, 2020

Conversation

pascalbaljet
Copy link
Contributor

@pascalbaljet pascalbaljet commented Sep 30, 2020

There is already a mapInto method to map each value into a new class, but with this method, you can pass the collection instance into a new class. Works great when combined with API Resources.

Before:

$categories = Category::query()
    ->orderBy('name')
    ->get()
    ->pipe(function (Collection $categories) {
        return new CategoryCollection($categories);
    });

After:

$categories = Category::query()
    ->orderBy('name')
    ->get()
    ->pipeInto(CategoryCollection::class);

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.

2 participants