Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Laravel 5.5.16 changes (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
besologic authored Oct 16, 2017
1 parent 428c64c commit b4f1480
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static function dot($array, $prepend = '')
}

/**
* Get all of the given array except for a specified array of items.
* Get all of the given array except for a specified array of keys.
*
* @param array $array
* @param array|string $keys
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
*/
protected static $proxies = [
'average', 'avg', 'contains', 'each', 'every', 'filter', 'first', 'flatMap',
'map', 'partition', 'reject', 'sortBy', 'sortByDesc', 'sum',
'keyBy', 'map', 'partition', 'reject', 'sortBy', 'sortByDesc', 'sum',
];

/**
Expand Down Expand Up @@ -1055,7 +1055,9 @@ public function only($keys)
*/
public function forPage($page, $perPage)
{
return $this->slice(($page - 1) * $perPage, $perPage);
$offset = max(0, ($page - 1) * $perPage);

return $this->slice($offset, $perPage);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ public function testFilter()
})->all());
}

public function testHigherOrderKeyBy()
{
$c = new Collection([
['id' => 'id1', 'name' => 'first'],
['id' => 'id2', 'name' => 'second'],
]);

$this->assertEquals(['id1' => 'first', 'id2' => 'second'], $c->keyBy->id->map->name->all());
}

public function testHigherOrderFilter()
{
$c = new Collection([
Expand Down Expand Up @@ -1758,6 +1768,7 @@ public function testKeys()
public function testPaginate()
{
$c = new Collection(['one', 'two', 'three', 'four']);
$this->assertEquals(['one', 'two'], $c->forPage(0, 2)->all());
$this->assertEquals(['one', 'two'], $c->forPage(1, 2)->all());
$this->assertEquals([2 => 'three', 3 => 'four'], $c->forPage(2, 2)->all());
$this->assertEquals([], $c->forPage(3, 2)->all());
Expand Down

0 comments on commit b4f1480

Please sign in to comment.