Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
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
laravel-adminpanel
Commits
f9adde7e
Unverified
Commit
f9adde7e
authored
Mar 13, 2018
by
Viral Solani
Committed by
GitHub
Mar 13, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #170 from indranshastri/develop
Changes for refactoring of the permission api
parents
41983ea1
86afc0bf
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
32 deletions
+45
-32
PermissionController.php
app/Http/Controllers/Api/V1/PermissionController.php
+38
-25
RolesController.php
app/Http/Controllers/Api/V1/RolesController.php
+4
-4
UsersController.php
app/Http/Controllers/Api/V1/UsersController.php
+2
-2
api.php
routes/api.php
+1
-1
No files found.
app/Http/Controllers/Api/V1/PermissionController.php
View file @
f9adde7e
...
@@ -23,43 +23,46 @@ class PermissionController extends APIController
...
@@ -23,43 +23,46 @@ class PermissionController extends APIController
}
}
/**
/**
* Return the
user
s.
* Return the
permission
s.
*
*
* @return \Illuminate\Http\Response
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
*/
public
function
index
(
Request
$request
)
public
function
index
(
Request
$request
)
{
{
$limit
=
$request
->
get
(
'paginate'
)
?
$request
->
get
(
'paginate'
)
:
25
;
$limit
=
$request
->
get
(
'paginate'
)
?
$request
->
get
(
'paginate'
)
:
25
;
return
PermissionResource
::
collection
(
return
PermissionResource
::
collection
(
$this
->
repository
->
get
Paginated
(
$limit
)
$this
->
repository
->
get
ForDataTable
()
->
paginate
(
$limit
)
);
);
}
}
/**
/**
* Return the specified resource.
* Return the specified resource.
*
*
* @param
User $user
* @param
Permission $permission
*
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\
Json
Response
*/
*/
public
function
show
(
Permission
$permission
)
public
function
show
(
Permission
$permission
)
{
{
return
new
PermissionResource
(
$permission
);
return
new
PermissionResource
(
$permission
);
}
}
/**
/**
* Creates the Resource for
Role
.
* Creates the Resource for
Permission
.
*
*
* @param Request $request
* @param Request $request
*
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\
Json
Response
*/
*/
public
function
store
(
Request
$request
)
public
function
store
(
Request
$request
)
{
{
$validation
=
$this
->
validat
ingRequest
(
$request
);
$validation
=
$this
->
validat
ePermission
(
$request
);
if
(
$validation
->
fails
())
{
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
()
);
return
$this
->
throwValidation
(
$validation
);
}
}
$this
->
repository
->
create
(
$request
->
all
());
$this
->
repository
->
create
(
$request
->
all
());
...
@@ -69,17 +72,17 @@ class PermissionController extends APIController
...
@@ -69,17 +72,17 @@ class PermissionController extends APIController
}
}
/**
/**
* @param
Role $role
* @param
Permission $permission
* @param UpdateRoleRequest $request
* @param UpdateRoleRequest $request
*
*
* @return
mixed
* @return
\Illuminate\Http\JsonResponse
*/
*/
public
function
update
(
Request
$request
,
Permission
$permission
)
public
function
update
(
Request
$request
,
Permission
$permission
)
{
{
$validation
=
$this
->
validat
ingRequest
(
$request
);
$validation
=
$this
->
validat
ePermission
(
$request
,
$permission
->
id
);
if
(
$validation
->
fails
())
{
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
()
);
return
$this
->
throwValidation
(
$validation
);
}
}
$this
->
repository
->
update
(
$permission
,
$request
->
all
());
$this
->
repository
->
update
(
$permission
,
$request
->
all
());
...
@@ -89,26 +92,36 @@ class PermissionController extends APIController
...
@@ -89,26 +92,36 @@ class PermissionController extends APIController
return
new
PermissionResource
(
$permission
);
return
new
PermissionResource
(
$permission
);
}
}
public
function
validatingRequest
(
Request
$request
)
{
$validation
=
Validator
::
make
(
$request
->
all
(),
[
'name'
=>
'required|max:191'
,
'display_name'
=>
'required|max:191'
,
]);
return
$validation
;
}
/**
/**
* @param Role $role
* @param Role $role
* @param DeleteRoleRequest $request
* @param DeleteRoleRequest $request
*
*
* @return
mixed
* @return
\Illuminate\Http\JsonResponse
*/
*/
public
function
destroy
(
Permission
$permission
,
Request
$request
)
public
function
destroy
(
Permission
$permission
,
Request
$request
)
{
{
$this
->
repository
->
delete
(
$permission
);
$this
->
repository
->
delete
(
$permission
);
return
[
'message'
=>
'success'
];
return
$this
->
respond
([
'message'
=>
trans
(
'alerts.backend.permissions.deleted'
),
]);
}
/**
* validateUser Permission Requests.
*
* @param Request $request
* @param Integer $id
*
* @return Validator object
*/
public
function
validatePermission
(
Request
$request
,
$id
=
0
)
{
$validation
=
Validator
::
make
(
$request
->
all
(),
[
'name'
=>
'required|max:191|unique:permissions,name,'
.
$id
,
'display_name'
=>
'required|max:191'
,
]);
return
$validation
;
}
}
}
}
app/Http/Controllers/Api/V1/RolesController.php
View file @
f9adde7e
...
@@ -55,13 +55,13 @@ class RolesController extends APIController
...
@@ -55,13 +55,13 @@ class RolesController extends APIController
*
*
* @param Request $request
* @param Request $request
*
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\
Json
Response
*/
*/
public
function
store
(
Request
$request
)
public
function
store
(
Request
$request
)
{
{
$validation
=
$this
->
validateRole
(
$request
);
$validation
=
$this
->
validateRole
(
$request
);
if
(
$validation
->
fails
())
{
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
()
);
return
$this
->
throwValidation
(
$validation
);
}
}
$this
->
repository
->
create
(
$request
->
all
());
$this
->
repository
->
create
(
$request
->
all
());
...
@@ -82,7 +82,7 @@ class RolesController extends APIController
...
@@ -82,7 +82,7 @@ class RolesController extends APIController
$validation
=
$this
->
validateRole
(
$request
);
$validation
=
$this
->
validateRole
(
$request
);
if
(
$validation
->
fails
())
{
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
()
);
return
$this
->
throwValidation
(
$validation
);
}
}
$this
->
repository
->
update
(
$role
,
$request
->
all
());
$this
->
repository
->
update
(
$role
,
$request
->
all
());
...
@@ -108,7 +108,7 @@ class RolesController extends APIController
...
@@ -108,7 +108,7 @@ class RolesController extends APIController
}
}
/**
/**
* validateUser
User
.
* validateUser
Role Requests
.
*
*
* @param $request
* @param $request
*
*
...
...
app/Http/Controllers/Api/V1/UsersController.php
View file @
f9adde7e
...
@@ -62,7 +62,7 @@ class UsersController extends APIController
...
@@ -62,7 +62,7 @@ class UsersController extends APIController
$validation
=
$this
->
validateUser
(
$request
);
$validation
=
$this
->
validateUser
(
$request
);
if
(
$validation
->
fails
())
{
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
()
);
return
$this
->
throwValidation
(
$validation
);
}
}
$this
->
repository
->
create
(
$request
);
$this
->
repository
->
create
(
$request
);
...
@@ -83,7 +83,7 @@ class UsersController extends APIController
...
@@ -83,7 +83,7 @@ class UsersController extends APIController
$validation
=
$this
->
validateUser
(
$request
,
'edit'
,
$user
->
id
);
$validation
=
$this
->
validateUser
(
$request
,
'edit'
,
$user
->
id
);
if
(
$validation
->
fails
())
{
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
()
);
return
$this
->
throwValidation
(
$validation
);
}
}
$updatedUser
=
$this
->
repository
->
update
(
$user
,
$request
);
$updatedUser
=
$this
->
repository
->
update
(
$user
,
$request
);
...
...
routes/api.php
View file @
f9adde7e
...
@@ -35,7 +35,7 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
...
@@ -35,7 +35,7 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
// Roles
// Roles
Route
::
resource
(
'roles'
,
'RolesController'
,
[
'except'
=>
[
'create'
,
'edit'
]]);
Route
::
resource
(
'roles'
,
'RolesController'
,
[
'except'
=>
[
'create'
,
'edit'
]]);
// Permission
// Permission
Route
::
resource
(
'permission'
,
'PermissionController'
);
Route
::
resource
(
'permission'
,
'PermissionController'
,
[
'except'
=>
[
'create'
,
'edit'
]]
);
// Page
// Page
Route
::
resource
(
'pages'
,
'PagesController'
);
Route
::
resource
(
'pages'
,
'PagesController'
);
...
...
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