Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
f2a84b50
Commit
f2a84b50
authored
Jan 11, 2015
by
duxet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix pagination of embedded elements
parent
738f224e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+8
-6
EmbeddedRelationsTest.php
tests/EmbeddedRelationsTest.php
+1
-1
No files found.
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
f2a84b50
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
use
MongoId
;
use
MongoId
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\
Database\Eloquent\Builde
r
;
use
Illuminate\
Pagination\Paginato
r
;
use
Illuminate\
Database\Eloquent\Relations\Relation
;
use
Illuminate\
Pagination\LengthAwarePaginator
;
class
EmbedsMany
extends
EmbedsOneOrMany
{
class
EmbedsMany
extends
EmbedsOneOrMany
{
...
@@ -275,17 +275,19 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -275,17 +275,19 @@ class EmbedsMany extends EmbedsOneOrMany {
*/
*/
public
function
paginate
(
$perPage
=
null
,
$columns
=
array
(
'*'
))
public
function
paginate
(
$perPage
=
null
,
$columns
=
array
(
'*'
))
{
{
$page
=
Paginator
::
resolveCurrentPage
();
$perPage
=
$perPage
?:
$this
->
related
->
getPerPage
();
$perPage
=
$perPage
?:
$this
->
related
->
getPerPage
();
$paginator
=
$this
->
related
->
getConnection
()
->
getPaginator
();
$results
=
$this
->
getEmbedded
();
$results
=
$this
->
getEmbedded
();
$
start
=
(
$paginator
->
getCurrentPage
()
-
1
)
*
$perPage
;
$
total
=
count
(
$results
)
;
$start
=
(
$page
-
1
)
*
$perPage
;
$sliced
=
array_slice
(
$results
,
$start
,
$perPage
);
$sliced
=
array_slice
(
$results
,
$start
,
$perPage
);
return
$paginator
->
make
(
$sliced
,
count
(
$results
),
$perPage
);
return
new
LengthAwarePaginator
(
$sliced
,
$total
,
$perPage
,
$page
,
[
'path'
=>
Paginator
::
resolveCurrentPath
()
]);
}
}
/**
/**
...
...
tests/EmbeddedRelationsTest.php
View file @
f2a84b50
...
@@ -746,7 +746,7 @@ class EmbeddedRelationsTest extends TestCase {
...
@@ -746,7 +746,7 @@ class EmbeddedRelationsTest extends TestCase {
$results
=
$user
->
addresses
()
->
paginate
(
2
);
$results
=
$user
->
addresses
()
->
paginate
(
2
);
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertEquals
(
3
,
$results
->
getT
otal
());
$this
->
assertEquals
(
3
,
$results
->
t
otal
());
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment