Unverified Commit 56d571e8 authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #175 from indranshastri/develop

Refactoring Blog categroies APIs
parents 820eb477 9c6b245e
......@@ -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,
]);
......
......@@ -44,7 +44,7 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
Route::resource('faqs', 'FaqsController');
// Blog Categories
Route::resource('blog_categories', 'BlogCategoriesController');
Route::resource('blog_categories', 'BlogCategoriesController', ['except' => ['create', 'edit']]);
// Blog Tags
Route::resource('blog_tags', 'BlogTagsController');
......
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