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
926a7bc6
Commit
926a7bc6
authored
Sep 27, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decouple the role controller from sentinel
parent
c24b6541
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
28 deletions
+79
-28
RolesController.php
Http/Controllers/Admin/RolesController.php
+15
-27
RoleRepository.php
Repositories/RoleRepository.php
+26
-0
SentinelRoleRepository.php
Repositories/Sentinel/SentinelRoleRepository.php
+38
-1
No files found.
Http/Controllers/Admin/RolesController.php
View file @
926a7bc6
...
...
@@ -8,6 +8,7 @@ use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use
Modules\Core\Permissions\PermissionManager
;
use
Modules\User\Http\Requests\CreateRolesRequest
;
use
Modules\User\Http\Requests\UpdateRoleRequest
;
use
Modules\User\Repositories\RoleRepository
;
class
RolesController
extends
AdminBaseController
{
...
...
@@ -19,12 +20,17 @@ class RolesController extends AdminBaseController
* @var PermissionManager
*/
private
$permissions
;
/**
* @var RoleRepository
*/
private
$role
;
public
function
__construct
(
PermissionManager
$permissions
)
public
function
__construct
(
PermissionManager
$permissions
,
RoleRepository
$role
)
{
parent
::
__construct
();
$this
->
roles
=
Sentinel
::
getRoleRepository
()
->
createModel
();
$this
->
permissions
=
$permissions
;
$this
->
role
=
$role
;
$this
->
beforeFilter
(
'permissions'
);
}
...
...
@@ -35,7 +41,7 @@ class RolesController extends AdminBaseController
*/
public
function
index
()
{
$roles
=
$this
->
role
s
->
all
();
$roles
=
$this
->
role
->
all
();
return
View
::
make
(
'user::admin.roles.index'
,
compact
(
'roles'
));
}
...
...
@@ -59,23 +65,13 @@ class RolesController extends AdminBaseController
public
function
store
(
CreateRolesRequest
$request
)
{
$data
=
array_merge
(
$request
->
all
(),
[
'permissions'
=>
$this
->
permissions
->
clean
(
$request
->
permissions
)]);
$this
->
roles
->
create
(
$data
);
Flash
::
success
(
'Role created'
);
$this
->
role
->
create
(
$data
);
Flash
::
success
(
'Role created'
);
return
Redirect
::
route
(
'dashboard.role.index'
);
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public
function
show
(
$id
)
{
}
/**
* Show the form for editing the specified resource.
*
...
...
@@ -84,7 +80,7 @@ class RolesController extends AdminBaseController
*/
public
function
edit
(
$id
)
{
if
(
!
$role
=
$this
->
role
s
->
find
(
$id
))
{
if
(
!
$role
=
$this
->
role
->
find
(
$id
))
{
return
Redirect
::
to
(
'user::admin.roles.index'
);
}
...
...
@@ -100,12 +96,9 @@ class RolesController extends AdminBaseController
*/
public
function
update
(
$id
,
UpdateRoleRequest
$request
)
{
$permissions
=
$this
->
permissions
->
clean
(
$request
->
permissions
);
$role
=
$this
->
roles
->
find
(
$id
);
$data
=
array_merge
(
$request
->
all
(),
[
'permissions'
=>
$this
->
permissions
->
clean
(
$request
->
permissions
)]);
$role
->
fill
(
$request
->
all
());
$role
->
permissions
=
$permissions
;
$role
->
save
();
$this
->
role
->
update
(
$id
,
$data
);
Flash
::
success
(
'Role updated!'
);
return
Redirect
::
route
(
'dashboard.role.index'
);
...
...
@@ -119,14 +112,9 @@ class RolesController extends AdminBaseController
*/
public
function
destroy
(
$id
)
{
if
(
$role
=
$this
->
roles
->
find
(
$id
))
{
$role
->
delete
();
Flash
::
success
(
'Role deleted!'
);
return
Redirect
::
route
(
'dashboard.role.index'
);
}
$this
->
role
->
delete
(
$id
);
Flash
::
success
(
'Role deleted!'
);
return
Redirect
::
route
(
'dashboard.role.index'
);
}
}
\ No newline at end of file
Repositories/RoleRepository.php
View file @
926a7bc6
<?php
namespace
Modules\User\Repositories
;
/**
* Interface RoleRepository
* @package Modules\User\Repositories
*/
interface
RoleRepository
{
/**
...
...
@@ -13,4 +17,26 @@ interface RoleRepository
* @return mixed
*/
public
function
create
(
$data
);
/**
* Find a role by its id
* @param $id
* @return mixed
*/
public
function
find
(
$id
);
/**
* Update a role
* @param $id
* @param $data
* @return mixed
*/
public
function
update
(
$id
,
$data
);
/**
* Delete a role
* @param $id
* @return mixed
*/
public
function
delete
(
$id
);
}
\ No newline at end of file
Repositories/Sentinel/SentinelRoleRepository.php
View file @
926a7bc6
...
...
@@ -30,6 +30,43 @@ class SentinelRoleRepository implements RoleRepository
*/
public
function
create
(
$data
)
{
// TODO: Implement create() method.
$this
->
role
->
create
(
$data
);
}
/**
* Find a role by its id
* @param $id
* @return mixed
*/
public
function
find
(
$id
)
{
return
$this
->
role
->
find
(
$id
);
}
/**
* Update a role
* @param $id
* @param $data
* @return mixed
*/
public
function
update
(
$id
,
$data
)
{
$role
=
$this
->
role
->
find
(
$id
);
$role
->
fill
(
$data
);
$role
->
save
();
}
/**
* Delete a role
* @param $id
* @return mixed
*/
public
function
delete
(
$id
)
{
$role
=
$this
->
role
->
find
(
$id
);
return
$role
->
delete
();
}
}
\ No newline at end of file
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