Skip to content

Commit

Permalink
Adds ability to sort DataCollection objects with the sort modifier. R…
Browse files Browse the repository at this point in the history
…eferences #3184.
  • Loading branch information
jackmcdade committed Mar 11, 2021
1 parent 01a7eb1 commit d298260
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,14 @@ public function sort($value, $params)

$value = $value instanceof Collection ? $value : collect($value);

// Working with a DataCollection
if (method_exists($value, 'multisort')) {
$value = $value->multisort(implode(':', $params));

return $value->values();
}

// Working with array data
if ($key === 'random') {
return $value->shuffle();
}
Expand Down

0 comments on commit d298260

Please sign in to comment.