Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
laravel-adminpanel
Commits
9150e260
Commit
9150e260
authored
Mar 08, 2018
by
cygnet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git commit changes related to blog category api
parent
28f87028
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
144 additions
and
0 deletions
+144
-0
BlogCategoriesController.php
app/Http/Controllers/Api/V1/BlogCategoriesController.php
+114
-0
BlogCategoriesResource.php
app/Http/Resources/BlogCategoriesResource.php
+27
-0
api.php
routes/api.php
+3
-0
No files found.
app/Http/Controllers/Api/V1/BlogCategoriesController.php
0 → 100755
View file @
9150e260
<?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'
];
}
}
app/Http/Resources/BlogCategoriesResource.php
0 → 100644
View file @
9150e260
<?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
,
];
}
}
routes/api.php
View file @
9150e260
...
...
@@ -45,5 +45,8 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
// Faqs
Route
::
resource
(
'faqs'
,
'FaqsController'
);
// Blog Categories
Route
::
resource
(
'blog_categories'
,
'BlogCategoriesController'
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment