Skip to content

Add callable support in sortByMany#2

Merged
sebastiandedeyne merged 3 commits into
spatie:mainfrom
drequenagonzalez:main
Jun 19, 2026
Merged

Add callable support in sortByMany#2
sebastiandedeyne merged 3 commits into
spatie:mainfrom
drequenagonzalez:main

Conversation

@drequenagonzalez

Copy link
Copy Markdown
Contributor

This change adds support for callable props exactly the same way like in Laravel Collections.

I've added it because I was getting an error using it like this:

$arr = [
    ['name' => 'ATest', 'age' => 34],
    ['name' => 'BTest', 'age' => 30],
    ['name' => 'ATest', 'age' => 36],
    ['name' => 'BTest', 'age' => 32],
]
|>sortBy([
    fn (array $a, array $b) => $a['name'] <=> $b['name'],
    fn (array $a, array $b) => $b['age'] <=> $a['age'],
]);

This change adds support for callable props like in Laravel Collections.
@sebastiandedeyne

Copy link
Copy Markdown
Member

Looks good! Could you also include a test in your PR?

@drequenagonzalez

Copy link
Copy Markdown
Contributor Author

@sebastiandedeyne Done! 🙌

@sebastiandedeyne

Copy link
Copy Markdown
Member

Thanks!

@sebastiandedeyne sebastiandedeyne merged commit b3e74d8 into spatie:main Jun 19, 2026
1 check passed
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