-
Notifications
You must be signed in to change notification settings - Fork 4.8k
[12.x] Add documentation for higher order static calls on collections #10478
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ | |||||
- [Extending Collections](#extending-collections) | ||||||
- [Available Methods](#available-methods) | ||||||
- [Higher Order Messages](#higher-order-messages) | ||||||
- [Higher Order Static Calls](#higher-order-static-calls) | ||||||
- [Lazy Collections](#lazy-collections) | ||||||
- [Introduction](#lazy-collection-introduction) | ||||||
- [Creating Lazy Collections](#creating-lazy-collections) | ||||||
|
@@ -3994,6 +3995,40 @@ $users = User::where('group', 'Development')->get(); | |||||
return $users->sum->votes; | ||||||
``` | ||||||
|
||||||
<a name="higher-order-static-calls"></a> | ||||||
## Higher Order Static Calls | ||||||
|
||||||
Collections also provide support for "higher order static calls", which are short-cuts for calling static methods elegantly if you’re storing class names in collections. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if "shortcut" isn't the more common version 🤔 but I'm not a native speaker, so 🤷🏻♂️
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used the same tone that we used in the section above that one, see: Higher Order Messages There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In dusk docs we used both Thank you for this. |
||||||
|
||||||
```php | ||||||
class Transformer1 | ||||||
{ | ||||||
public static function transform(string $name): string | ||||||
{ | ||||||
return strtoupper($name); | ||||||
} | ||||||
} | ||||||
|
||||||
class Transformer2 | ||||||
{ | ||||||
public static function transform(string $name): string | ||||||
{ | ||||||
return strtolower($name); | ||||||
} | ||||||
} | ||||||
|
||||||
$transformers = collect([Transformer1::class, Transformer2::class]); | ||||||
|
||||||
$results = $transformers->map->transform('taylor'); | ||||||
|
||||||
$results->dd(); | ||||||
|
||||||
// array:2 [ | ||||||
// 0 => "TAYLOR" | ||||||
// 1 => "taylor" | ||||||
// ] | ||||||
``` | ||||||
|
||||||
<a name="lazy-collections"></a> | ||||||
## Lazy Collections | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to use an actual apostrophe here 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, but we do not use
you’re
we useyou're
across the whole docs see:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you're not.
That's what I meant 😉