Skip to content

Commit e3218cd

Browse files
committed
Fix page variable detection in pagination
1 parent 5d4c283 commit e3218cd

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

src/CachedBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ public function paginate(
126126
return parent::paginate($perPage, $columns, $pageName, $page);
127127
}
128128

129-
$page = request($pageName, $page ?: 1);
129+
$page = request()->input($pageName)
130+
?: $page
131+
?: 1;
130132

131133
if (is_array($page)) {
132134
$page = $this->recursiveImplodeWithKey($page);
133135
}
134-
135136
$cacheKey = $this->makeCacheKey($columns, null, "-paginate_by_{$perPage}_{$pageName}_{$page}");
136137

137138
return $this->cachedValue(func_get_args(), $cacheKey);

tests/CreatesApplication.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use GeneaLabs\LaravelModelCaching\Providers\Service as LaravelModelCachingService;
44
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
55
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
6+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Observers\AuthorObserver;
67
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile;
78
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher;
89
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store;
@@ -38,6 +39,7 @@ public function setUp()
3839

3940
$this->cache()->flush();
4041
$publishers = factory(Publisher::class, 10)->create();
42+
(new Author)->observe(AuthorObserver::class);
4143
factory(Author::class, 10)->create()
4244
->each(function ($author) use ($publishers) {
4345
factory(Book::class, random_int(5, 25))->make()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures\Observers;
2+
3+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4+
5+
class AuthorObserver
6+
{
7+
public function saving(Author $author)
8+
{
9+
$author->email .= "";
10+
}
11+
12+
public function retrieved(Author $author)
13+
{
14+
$author->email .= "";
15+
}
16+
}

tests/Integration/CachedBuilder/PaginateTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
*/
2121
class PaginateTest extends IntegrationTestCase
2222
{
23-
24-
2523
public function testPaginationIsCached()
2624
{
2725
$authors = (new Author)
@@ -44,6 +42,7 @@ public function testPaginationIsCached()
4442
$this->assertEquals($liveResults->pluck("name"), $authors->pluck("name"));
4543
}
4644

45+
/** @group test */
4746
public function testPaginationReturnsCorrectLinks()
4847
{
4948
if (starts_with(app()->version(), "5.6")

tests/Integration/CachedModelTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration;
22

33
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4-
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\PrefixedAuthor;
54
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
5+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Observers\AuthorObserver;
6+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\PrefixedAuthor;
67
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile;
78
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher;
89
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store;
@@ -16,7 +17,7 @@
1617

1718
class CachedModelTest extends IntegrationTestCase
1819
{
19-
20+
2021

2122
public function testAllModelResultsCreatesCache()
2223
{
@@ -190,4 +191,18 @@ public function testModelCacheDoesInvalidateWhenNoCooldownPeriod()
190191
$this->assertCount(11, $authorsAfterCreate);
191192
$this->assertCount(11, $uncachedAuthors);
192193
}
194+
195+
// /** @group test */
196+
// public function testModelObserver()
197+
// {
198+
// (new Author)->observe(AuthorObserver::class);
199+
// $authors = (new Author)->get();
200+
// $author1 = $authors->first();
201+
// $author2 = $authors->last();
202+
//
203+
// $author1->save();
204+
//
205+
// $this->assertEquals("saving@noemail.com", $author1->email);
206+
// $this->assertEquals("retrieved@noemail.com", $author2->email);
207+
// }
193208
}

0 commit comments

Comments
 (0)