Commit 86afc0bf authored by cygnet's avatar cygnet

changes for Refactoring permssion and minute change in role and changes for...

changes for Refactoring permssion and minute change in role  and changes for sending errors on user role and permission
parent 41983ea1
...@@ -23,43 +23,46 @@ class PermissionController extends APIController ...@@ -23,43 +23,46 @@ class PermissionController extends APIController
} }
/** /**
* Return the users. * Return the permissions.
* *
* @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->getPaginated($limit) $this->repository->getForDataTable()->paginate($limit)
); );
} }
/** /**
* Return the specified resource. * Return the specified resource.
* *
* @param User $user * @param Permission $permission
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\JsonResponse
*/ */
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\JsonResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
$validation = $this->validatingRequest($request); $validation = $this->validatePermission($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->validatingRequest($request); $validation = $this->validatePermission($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;
} }
} }
...@@ -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\JsonResponse
*/ */
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
* *
......
...@@ -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);
......
...@@ -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');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment