Skip to content

Commit

Permalink
Merge branch '5.2' of github.com:laravel/framework into 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 20, 2016
2 parents 2715509 + 468e890 commit ce1f3b2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,10 @@ public function makeVisible($attributes)
{
$this->hidden = array_diff($this->hidden, (array) $attributes);

if (! empty($this->visible)) {
$this->addVisible($attributes);
}

return $this;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Illuminate\Support\Collection;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Support\Arrayable;
Expand Down Expand Up @@ -1410,6 +1411,11 @@ public function forPage($page, $perPage = 15)
*/
public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
{
$this->orders = Collection::make($this->orders)
->reject(function ($order) use ($column) {
return $order['column'] === $column;
})->values()->all();

return $this->where($column, '>', $lastId)
->orderBy($column, 'asc')
->take($perPage);
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/DatabaseEloquentCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,19 @@ public function testNonModelRelatedMethods()
$this->assertEquals(get_class($a->zip(['a', 'b'], ['c', 'd'])), BaseCollection::class);
$this->assertEquals(get_class($b->flip()), BaseCollection::class);
}

public function testMakeVisibleRemovesHiddenAndIncludesVisible()
{
$c = new Collection([new TestEloquentCollectionModel]);
$c = $c->makeVisible('hidden');

$this->assertEquals([], $c[0]->getHidden());
$this->assertEquals(['visible', 'hidden'], $c[0]->getVisible());
}
}

class TestEloquentCollectionModel extends Illuminate\Database\Eloquent\Model
{
protected $visible = ['visible'];
protected $hidden = ['hidden'];
}
12 changes: 12 additions & 0 deletions tests/Database/DatabaseEloquentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,18 @@ public function testRelationsArePreloadedInGlobalScope()
$this->assertCount(1, $result->getRelations());
}

public function testForPageAfterIdCorrectlyPaginates()
{
EloquentTestUser::create(['id' => 1, 'email' => '[email protected]']);
EloquentTestUser::create(['id' => 2, 'email' => '[email protected]']);

$results = EloquentTestUser::forPageAfterId(15, 1);
$this->assertEquals(1, count($results));

$results = EloquentTestUser::orderBy('id', 'desc')->forPageAfterId(15, 1);
$this->assertEquals(1, count($results));
}

/**
* Helpers...
*/
Expand Down

0 comments on commit ce1f3b2

Please sign in to comment.