Unverified Commit dfdc6994 authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #154 from indranshastri/develop

Pages Api Changes 
parents 1cb96da9 4b1c03f3
<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Resources\BlogCategoriesResource;
use App\Models\BlogCategories\BlogCategory;
use App\Repositories\Backend\BlogCategories\BlogCategoriesRepository;
use Illuminate\Http\Request;
use Validator;
class BlogCategoriesController extends APIController
{
protected $repository;
/**
* __construct.
*
* @param $repository
*/
public function __construct(BlogCategoriesRepository $repository)
{
$this->repository = $repository;
}
/**
* Return the users.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
return BlogCategoriesResource::collection(
$this->repository->getForDataTable()->paginate($limit)
);
}
/**
* Return the specified resource.
*
* @param User $user
*
* @return \Illuminate\Http\Response
*/
public function show(BlogCategory $blog_category)
{
return new BlogCategoriesResource($blog_category);
}
/**
* Creates the Resource for BlogCategory.
*
* @param Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
$this->repository->create($request->all());
return new BlogCategoriesResource(BlogCategory::orderBy('created_at', 'desc')->first());
}
/**
* @param BlogCategory $blog_category
* @param UpdateBlogCategoryRequest $request
*
* @return mixed
*/
public function update(Request $request, BlogCategory $blog_category)
{
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
$this->repository->update($blog_category, $request->all());
$blog_category = BlogCategory::findOrfail($blog_category->id);
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
*
* @return mixed
*/
public function destroy(BlogCategory $blog_category, Request $request)
{
$this->repository->delete($blog_category);
return ['message'=>'success'];
}
}
<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Resources\FaqsResource;
use App\Models\Faqs\Faq;
use App\Repositories\Backend\Faqs\FaqsRepository;
use Illuminate\Http\Request;
use Validator;
class FaqsController extends APIController
{
protected $repository;
/**
* __construct.
*
* @param $repository
*/
public function __construct(FaqsRepository $repository)
{
$this->repository = $repository;
}
/**
* Return the users.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
return FaqsResource::collection(
$this->repository->getForDataTable()->paginate($limit)
);
}
/**
* Return the specified resource.
*
* @param User $user
*
* @return \Illuminate\Http\Response
*/
public function show(Faq $faq)
{
return new FaqsResource($faq);
}
/**
* Creates the Resource for Faq.
*
* @param Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
$this->repository->create($request->all());
return new FaqsResource(Faq::orderBy('created_at', 'desc')->first());
}
/**
* @param Faq $faq
* @param UpdateFaqRequest $request
*
* @return mixed
*/
public function update(Request $request, Faq $faq)
{
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
$this->repository->update($faq, $request->all());
$faq = Faq::findOrfail($faq->id);
return new FaqsResource($faq);
}
public function validatingRequest(Request $request)
{
$validation = Validator::make($request->all(), [
'question' => 'required|max:191',
'answer' => 'required',
]);
return $validation;
}
/**
* @param Faq $faq
* @param DeleteFaqRequest $request
*
* @return mixed
*/
public function destroy(Faq $faq, Request $request)
{
$this->repository->delete($faq);
return ['message'=>'success'];
}
}
<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Resources\PagesResource;
use App\Models\Page\Page;
use App\Repositories\Backend\Pages\PagesRepository;
use Illuminate\Http\Request;
use Validator;
class PagesController extends APIController
{
protected $repository;
/**
* __construct.
*
* @param $repository
*/
public function __construct(PagesRepository $repository)
{
$this->repository = $repository;
}
/**
* Return the users.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
return PagesResource::collection(
$this->repository->getForDataTable()->paginate($limit)
);
}
/**
* Return the specified resource.
*
* @param User $user
*
* @return \Illuminate\Http\Response
*/
public function show(Page $page)
{
return new PagesResource($page);
}
/**
* Creates the Resourse for Page.
*
* @param Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
$this->repository->create($request->all());
return new PagesResource(Page::orderBy('created_at', 'desc')->first());
}
/**
* @param Page $page
* @param UpdatePageRequest $request
*
* @return mixed
*/
public function update(Request $request, Page $page)
{
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
$this->repository->update($page, $request->all());
$page = Page::findOrfail($page->id);
return new PagesResource($page);
}
public function validatingRequest(Request $request)
{
$validation = Validator::make($request->all(), [
'title' => 'required|max:191',
'description' => 'required',
]);
return $validation;
}
/**
* @param Page $page
* @param DeletePageRequest $request
*
* @return mixed
*/
public function destroy(Page $page, Request $request)
{
$this->repository->delete($page);
return ['message'=>'success'];
}
}
......@@ -49,7 +49,7 @@ class PermissionController extends APIController
}
/**
* Creates the Resourse for Role.
* Creates the Resource for Role.
*
* @param Request $request
*
......@@ -57,7 +57,7 @@ class PermissionController extends APIController
*/
public function store(Request $request)
{
$validation = $this->valiatingRequest($request);
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
......@@ -76,7 +76,7 @@ class PermissionController extends APIController
*/
public function update(Request $request, Permission $permission)
{
$validation = $this->valiatingRequest($request);
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
......@@ -89,7 +89,7 @@ class PermissionController extends APIController
return new PermissionResource($permission);
}
public function valiatingRequest(Request $request)
public function validatingRequest(Request $request)
{
$validation = Validator::make($request->all(), [
'name' => 'required|max:191',
......
......@@ -57,7 +57,7 @@ class RolesController extends APIController
*/
public function store(Request $request)
{
$validation = $this->valiatingRequest($request);
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
......@@ -75,7 +75,7 @@ class RolesController extends APIController
*/
public function update(Request $request, Role $role)
{
$validation = $this->valiatingRequest($request);
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
......@@ -88,7 +88,7 @@ class RolesController extends APIController
return new RoleResource($role);
}
public function valiatingRequest(Request $request)
public function validatingRequest(Request $request)
{
$permissions = '';
......
......@@ -32,7 +32,7 @@ class UsersController extends APIController
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
return UserResource::collection(
$this->repository->getPaginated($limit)
$this->repository->getForDataTable(1, false)->paginate($limit)
);
}
......@@ -53,12 +53,43 @@ class UsersController extends APIController
return $maindata;
}
/**
* Return the specified resource.
*
* @param Request
*
* @return \Illuminate\Http\Response
*/
public function deactivatedUserList(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
return UserResource::collection(
$this->repository->getForDataTable(0,false)->paginate($limit)
);
}
/**
* Return the specified resource.
*
* @param User $user
*
* @return \Illuminate\Http\Response
*/
public function deleteUserList(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
return UserResource::collection(
$this->repository->getForDataTable(0, true)->paginate($limit)
);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, User $user)
{
$validation = $this->valiatingRequest($request, 'edit', $user->id);
$validation = $this->validatingRequest($request, 'edit', $user->id);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
......@@ -76,7 +107,7 @@ class UsersController extends APIController
*/
public function store(Request $request)
{
$validation = $this->valiatingRequest($request);
$validation = $this->validatingRequest($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
......@@ -89,7 +120,7 @@ class UsersController extends APIController
/**
* Validation function to validate user input.
*/
public function valiatingRequest(Request $request, $string = '', $id = 0)
public function validatingRequest(Request $request, $string = '', $id = 0)
{
$password = ($string == 'edit') ? '' : 'required|min:6|confirmed';
$validation = Validator::make($request->all(), [
......
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class BlogCategoriesResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
*
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'status' => ($this->isActive()) ? "Active" : "InActive",
'created_at' => optional($this->created_at)->toDateString(),
'created_by' => (isset($this->creator)) ? optional($this->creator)->first_name : $this->user_name,
];
}
}
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class FaqsResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
*
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'question' => $this->question,
'answer' => $this->answer,
'status' => ($this->isActive()) ? "Active" : "InActive",
'created_at' => $this->created_at->toDateString(),
];
}
}
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class PagesResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
*
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'status_label' => $this->status_label,
'status' => ($this->isActive())?"Active":"InActive",
'created_at' => $this->created_at->toDateString(),
'created_by' => is_int($this->created_by)?optional($this->owner)->first_name:$this->created_by,
];
}
}
......@@ -29,11 +29,24 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
});
// Users
Route::group(['prefix' => 'users'], function () {
Route::get('deactiveUsers', 'UsersController@deactivatedUserList');
Route::get('deleteUsers', 'UsersController@deleteUserList');
});
Route::resource('users', 'UsersController');
// Roles
Route::resource('roles', 'RolesController');
// Permission
Route::resource('permission', 'PermissionController');
// Page
Route::resource('pages', 'PagesController');
// Faqs
Route::resource('faqs', 'FaqsController');
// Blog Categories
Route::resource('blog_categories', 'BlogCategoriesController');
});
});
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