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
a99a8018
Commit
a99a8018
authored
Mar 13, 2018
by
cygnet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring done on api/roles controller
parent
ee136503
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
34 deletions
+46
-34
RolesController.php
app/Http/Controllers/Api/V1/RolesController.php
+41
-26
api.php
routes/api.php
+5
-8
No files found.
app/Http/Controllers/Api/V1/RolesController.php
View file @
a99a8018
...
...
@@ -22,26 +22,29 @@ class RolesController extends APIController
$this
->
repository
=
$repository
;
}
/**
* Return the
user
s.
* Return the
role
s.
*
* @return \Illuminate\Http\Response
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public
function
index
(
Request
$request
)
{
$limit
=
$request
->
get
(
'paginate'
)
?
$request
->
get
(
'paginate'
)
:
25
;
return
RoleResource
::
collection
(
$this
->
repository
->
get
Paginated
(
$limit
)
$this
->
repository
->
get
ForDataTable
()
->
paginate
(
$limit
)
);
}
/**
* Return the specified resource.
*
* @param
User $user
* @param
Role $role
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\
Json
Response
*/
public
function
show
(
Role
$role
)
{
...
...
@@ -49,7 +52,7 @@ class RolesController extends APIController
}
/**
* Creates the Resour
s
e for Role.
* Creates the Resour
c
e for Role.
*
* @param Request $request
*
...
...
@@ -57,7 +60,7 @@ class RolesController extends APIController
*/
public
function
store
(
Request
$request
)
{
$validation
=
$this
->
validat
ingRequest
(
$request
);
$validation
=
$this
->
validat
eRole
(
$request
);
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
());
}
...
...
@@ -68,14 +71,16 @@ class RolesController extends APIController
}
/**
* Update User.
*
* @param Request $request
* @param Role $role
* @param UpdateRoleRequest $request
*
* @return
mixed
* @return
\Illuminate\Http\JsonResponse
*/
public
function
update
(
Request
$request
,
Role
$role
)
{
$validation
=
$this
->
validat
ingRequest
(
$request
);
$validation
=
$this
->
validat
eRole
(
$request
);
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
());
...
...
@@ -88,7 +93,30 @@ class RolesController extends APIController
return
new
RoleResource
(
$role
);
}
public
function
validatingRequest
(
Request
$request
)
/**
* @param Role $role
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public
function
destroy
(
Role
$role
,
Request
$request
)
{
$this
->
repository
->
delete
(
$role
);
return
$this
->
respond
([
'message'
=>
trans
(
'alerts.backend.roles.deleted'
),
]);
}
/**
* validateUser User.
*
* @param $request
*
* @return Validator object
*/
public
function
validateRole
(
Request
$request
)
{
$permissions
=
''
;
...
...
@@ -103,17 +131,4 @@ class RolesController extends APIController
return
$validation
;
}
/**
* @param Role $role
* @param DeleteRoleRequest $request
*
* @return mixed
*/
public
function
destroy
(
Role
$role
,
Request
$request
)
{
$this
->
repository
->
delete
(
$role
);
return
[
'message'
=>
'success'
];
}
}
routes/api.php
View file @
a99a8018
...
...
@@ -27,17 +27,14 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
Route
::
post
(
'password/email'
,
'ForgotPasswordController@sendResetLinkEmail'
);
// Route::post('password/reset', 'ResetPasswordController@reset')->name('password.reset');
});
Route
::
resource
(
'users'
,
'UsersController'
,
[
'except'
=>
[
'edit'
,
'udpate'
]]);
// Users
Route
::
group
([
'prefix'
=>
'users'
],
function
()
{
Route
::
get
(
'deactiveUsers'
,
'UsersController@deactivatedUserList
'
);
Route
::
get
(
'deleteUsers'
,
'UsersController@deleteUserList
'
);
});
Route
::
resource
(
'users'
,
'UsersController'
,
[
'except'
=>
[
'create'
,
'edit'
]]);
Route
::
get
(
'deactivatedUsers'
,
'DeactivatedUsersController@index
'
);
Route
::
get
(
'deletedUsers'
,
'DeletedUsersController@index
'
);
// Roles
Route
::
resource
(
'roles'
,
'RolesController'
);
Route
::
resource
(
'roles'
,
'RolesController'
,
[
'except'
=>
[
'create'
,
'edit'
]]
);
// Permission
Route
::
resource
(
'permission'
,
'PermissionController'
);
...
...
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