Commit 9c2bb3d7 authored by cygnet's avatar cygnet

changes done for refactoring the blog categroies api and minor changes in roles and permmison api

parent 820eb477
......@@ -23,9 +23,11 @@ class BlogCategoriesController extends APIController
}
/**
* Return the users.
* Return the blog-categories.
*
* @param Request $request
*
* @return \Illuminate\Http\Response
*@return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
{
......@@ -39,9 +41,9 @@ class BlogCategoriesController extends APIController
/**
* Return the specified resource.
*
* @param User $user
* @param BlogCategory $blog_category
*
* @return \Illuminate\Http\Response
*@return \Illuminate\Http\JsonResponse
*/
public function show(BlogCategory $blog_category)
{
......@@ -53,11 +55,11 @@ class BlogCategoriesController extends APIController
*
* @param Request $request
*
* @return \Illuminate\Http\Response
*@return \Illuminate\Http\JsonResponse
*/
public function store(Request $request)
{
$validation = $this->validatingRequest($request);
$validation = $this->validateBlogCategory($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
......@@ -68,14 +70,14 @@ class BlogCategoriesController extends APIController
}
/**
* @param BlogCategory $blog_category
* @param UpdateBlogCategoryRequest $request
* @param BlogCategory $blog_category
* @param Request $request
*
* @return mixed
*/
public function update(Request $request, BlogCategory $blog_category)
{
$validation = $this->validatingRequest($request);
$validation = $this->validateBlogCategory($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
......@@ -88,18 +90,9 @@ class BlogCategoriesController extends APIController
return new BlogCategoriesResource($blog_category);
}
public function validatingRequest(Request $request)
{
$validation = Validator::make($request->all(), [
'name' => 'required|max:191',
]);
return $validation;
}
/**
* @param BlogCategory $blog_category
* @param DeleteBlogCategoryRequest $request
* @param Request $request
*
* @return mixed
*/
......@@ -107,6 +100,24 @@ class BlogCategoriesController extends APIController
{
$this->repository->delete($blog_category);
return ['message'=>'success'];
return $this->respond([
'message' => trans('alerts.backend.blogcategories.deleted'),
]);
}
/**
* validateUser Permission Requests.
*
* @param Request $request
*
* @return Validator object
*/
public function validateBlogCategory(Request $request)
{
$validation = Validator::make($request->all(), [
'name' => 'required|max:191',
]);
return $validation;
}
}
......@@ -72,7 +72,7 @@ class PermissionController extends APIController
/**
* @param Permission $permission
* @param UpdateRoleRequest $request
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
......
......@@ -79,7 +79,7 @@ class RolesController extends APIController
*/
public function update(Request $request, Role $role)
{
$validation = $this->validateRole($request);
$validation = $this->validateRole($request, $role->id);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
......@@ -110,11 +110,12 @@ class RolesController extends APIController
/**
* validateUser Role Requests.
*
* @param $request
*
* @param Request $request
* @param int $id
*
* @return Validator object
*/
public function validateRole(Request $request)
public function validateRole(Request $request,$id=0)
{
$permissions = '';
......@@ -123,7 +124,7 @@ class RolesController extends APIController
}
$validation = Validator::make($request->all(), [
'name' => 'required|max:191',
'name' => 'required|max:191|unique:roles,name,'.$id,
'permissions' => $permissions,
]);
......
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