Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
Platform
Commits
28debcdb
Unverified
Commit
28debcdb
authored
Oct 11, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding new method to fetch roles for server side table
parent
9623e665
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
RoleRepository.php
Modules/User/Repositories/RoleRepository.php
+10
-0
SentinelRoleRepository.php
...les/User/Repositories/Sentinel/SentinelRoleRepository.php
+38
-0
No files found.
Modules/User/Repositories/RoleRepository.php
View file @
28debcdb
...
...
@@ -2,6 +2,9 @@
namespace
Modules\User\Repositories
;
use
Illuminate\Contracts\Pagination\LengthAwarePaginator
;
use
Illuminate\Http\Request
;
/**
* Interface RoleRepository
* @package Modules\User\Repositories
...
...
@@ -48,4 +51,11 @@ interface RoleRepository
* @return mixed
*/
public
function
findByName
(
$name
);
/**
* Paginating, ordering and searching through pages for server side index table
* @param Request $request
* @return LengthAwarePaginator
*/
public
function
serverPaginationFilteringFor
(
Request
$request
)
:
LengthAwarePaginator
;
}
Modules/User/Repositories/Sentinel/SentinelRoleRepository.php
View file @
28debcdb
...
...
@@ -3,6 +3,9 @@
namespace
Modules\User\Repositories\Sentinel
;
use
Cartalyst\Sentinel\Laravel\Facades\Sentinel
;
use
Illuminate\Contracts\Pagination\LengthAwarePaginator
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Http\Request
;
use
Modules\User\Events\RoleIsCreating
;
use
Modules\User\Events\RoleIsUpdating
;
use
Modules\User\Events\RoleWasCreated
;
...
...
@@ -30,6 +33,33 @@ class SentinelRoleRepository implements RoleRepository
return
$this
->
role
->
all
();
}
/**
* Paginating, ordering and searching through pages for server side index table
* @param Request $request
* @return LengthAwarePaginator
*/
public
function
serverPaginationFilteringFor
(
Request
$request
)
:
LengthAwarePaginator
{
$roles
=
$this
->
allWithBuilder
();
if
(
$request
->
get
(
'search'
)
!==
null
)
{
$term
=
$request
->
get
(
'search'
);
$roles
->
where
(
'name'
,
'LIKE'
,
"%
{
$term
}
%"
)
->
orWhere
(
'slug'
,
'LIKE'
,
"%
{
$term
}
%"
)
->
orWhere
(
'id'
,
$term
);
}
if
(
$request
->
get
(
'order_by'
)
!==
null
&&
$request
->
get
(
'order'
)
!==
'null'
)
{
$order
=
$request
->
get
(
'order'
)
===
'ascending'
?
'asc'
:
'desc'
;
$roles
->
orderBy
(
$request
->
get
(
'order_by'
),
$order
);
}
else
{
$roles
->
orderBy
(
'created_at'
,
'desc'
);
}
return
$roles
->
paginate
(
$request
->
get
(
'per_page'
,
10
));
}
/**
* Create a role resource
* @return mixed
...
...
@@ -95,4 +125,12 @@ class SentinelRoleRepository implements RoleRepository
{
return
Sentinel
::
findRoleByName
(
$name
);
}
/**
* @inheritdoc
*/
public
function
allWithBuilder
()
:
Builder
{
return
$this
->
role
->
newQuery
();
}
}
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