Commit 5b4fb941 authored by cygnet's avatar cygnet

Refactoring the Pages api

parent 9c6b245e
......@@ -70,6 +70,8 @@ class BlogCategoriesController extends APIController
}
/**
* Update BlogCategory
*
* @param BlogCategory $blog_category
* @param Request $request
*
......@@ -91,6 +93,8 @@ class BlogCategoriesController extends APIController
}
/**
* Delete BlogCategory
*
* @param BlogCategory $blog_category
* @param Request $request
*
......@@ -106,7 +110,7 @@ class BlogCategoriesController extends APIController
}
/**
* validateUser Permission Requests.
* validateUser BlogCategory Requests.
*
* @param Request $request
*
......
......@@ -23,9 +23,9 @@ class PagesController extends APIController
}
/**
* Return the users.
* Return the pages.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
{
......@@ -39,9 +39,9 @@ class PagesController extends APIController
/**
* Return the specified resource.
*
* @param User $user
* @param Pages $page
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function show(Page $page)
{
......@@ -49,15 +49,15 @@ class PagesController extends APIController
}
/**
* Creates the Resourse for Page.
* Creates the Resource for Page.
*
* @param Request $request
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function store(Request $request)
{
$validation = $this->validatingRequest($request);
$validation = $this->validatePages($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
......@@ -68,14 +68,16 @@ class PagesController extends APIController
}
/**
* @param Page $page
* @param UpdatePageRequest $request
* Update Page.
*
* @param Page $page
* @param Request $request
*
* @return mixed
* @return \Illuminate\Http\JsonResponse
*/
public function update(Request $request, Page $page)
{
$validation = $this->validatingRequest($request);
$validation = $this->validatePages($request, $page->id);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
......@@ -88,26 +90,41 @@ class PagesController extends APIController
return new PagesResource($page);
}
public function validatingRequest(Request $request)
{
$validation = Validator::make($request->all(), [
'title' => 'required|max:191',
'description' => 'required',
]);
return $validation;
}
/**
* Delete Page.
*
* @param Page $page
* @param DeletePageRequest $request
*
* @return mixed
* @return \Illuminate\Http\JsonResponse
*/
public function destroy(Page $page, Request $request)
{
$this->repository->delete($page);
return ['message'=>'success'];
return $this->respond([
'message' => trans('alerts.backend.pages.deleted'),
]);
}
/**
* validateUser Pages Requests.
*
* @param Request $request
* @param int $id
*
* @return \Illuminate\Http\JsonResponse
*/
public function validatePages(Request $request,$id=0)
{
$validation = Validator::make($request->all(), [
'title' => 'required|max:191|unique:pages,title,'.$id,
'description' => 'required',
]);
return $validation;
}
}
......@@ -71,6 +71,8 @@ class PermissionController extends APIController
}
/**
* Updates Permission
*
* @param Permission $permission
* @param Request $request
*
......@@ -92,6 +94,8 @@ class PermissionController extends APIController
}
/**
* Delete permission
*
* @param Role $role
* @param DeleteRoleRequest $request
*
......
......@@ -70,7 +70,7 @@ class RolesController extends APIController
}
/**
* Update User.
* Update Role.
*
* @param Request $request
* @param Role $role
......@@ -93,6 +93,8 @@ class RolesController extends APIController
}
/**
* Delete Role.
*
* @param Role $role
* @param Request $request
*
......
......@@ -38,18 +38,18 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
Route::resource('permission', 'PermissionController', ['except' => ['create', 'edit']]);
// Page
Route::resource('pages', 'PagesController');
Route::resource('pages', 'PagesController', ['except' => ['create', 'edit']]);
// Faqs
Route::resource('faqs', 'FaqsController');
Route::resource('faqs', 'FaqsController', ['except' => ['create', 'edit']]);
// Blog Categories
Route::resource('blog_categories', 'BlogCategoriesController', ['except' => ['create', 'edit']]);
// Blog Tags
Route::resource('blog_tags', 'BlogTagsController');
Route::resource('blog_tags', 'BlogTagsController', ['except' => ['create', 'edit']]);
// Blogs
Route::resource('blogs', 'BlogsController');
Route::resource('blogs', 'BlogsController', ['except' => ['create', 'edit']]);
});
});
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