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
82677a91
Unverified
Commit
82677a91
authored
Mar 08, 2018
by
Viral Solani
Committed by
GitHub
Mar 08, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #156 from indranshastri/develop
Created the apis for blog and blog tags
parents
6bd33ef4
327ad995
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
301 additions
and
0 deletions
+301
-0
BlogTagsController.php
app/Http/Controllers/Api/V1/BlogTagsController.php
+114
-0
BlogsController.php
app/Http/Controllers/Api/V1/BlogsController.php
+126
-0
BlogTagsResource.php
app/Http/Resources/BlogTagsResource.php
+27
-0
BlogsResource.php
app/Http/Resources/BlogsResource.php
+28
-0
api.php
routes/api.php
+6
-0
No files found.
app/Http/Controllers/Api/V1/BlogTagsController.php
0 → 100755
View file @
82677a91
<?php
namespace
App\Http\Controllers\Api\V1
;
use
App\Http\Resources\BlogTagsResource
;
use
App\Models\BlogTags\BlogTag
;
use
App\Repositories\Backend\BlogTags\BlogTagsRepository
;
use
Illuminate\Http\Request
;
use
Validator
;
class
BlogTagsController
extends
APIController
{
protected
$repository
;
/**
* __construct.
*
* @param $repository
*/
public
function
__construct
(
BlogTagsRepository
$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
BlogTagsResource
::
collection
(
$this
->
repository
->
getForDataTable
()
->
paginate
(
$limit
)
);
}
/**
* Return the specified resource.
*
* @param User $user
*
* @return \Illuminate\Http\Response
*/
public
function
show
(
BlogTag
$blog_tag
)
{
return
new
BlogTagsResource
(
$blog_tag
);
}
/**
* Creates the Resource for BlogTag.
*
* @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
BlogTagsResource
(
BlogTag
::
orderBy
(
'created_at'
,
'desc'
)
->
first
());
}
/**
* @param BlogTag $blog_tag
* @param UpdateBlogTagRequest $request
*
* @return mixed
*/
public
function
update
(
Request
$request
,
BlogTag
$blog_tag
)
{
$validation
=
$this
->
validatingRequest
(
$request
,
$blog_tag
->
id
);
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
());
}
$this
->
repository
->
update
(
$blog_tag
,
$request
->
all
());
$blog_tag
=
BlogTag
::
findOrfail
(
$blog_tag
->
id
);
return
new
BlogTagsResource
(
$blog_tag
);
}
public
function
validatingRequest
(
Request
$request
,
$id
=
0
)
{
$validation
=
Validator
::
make
(
$request
->
all
(),
[
'name'
=>
'required|max:191|unique:blog_tags,name,'
.
$id
,
]);
return
$validation
;
}
/**
* @param BlogTag $blog_tag
* @param DeleteBlogTagRequest $request
*
* @return mixed
*/
public
function
destroy
(
BlogTag
$blog_tag
,
Request
$request
)
{
$this
->
repository
->
delete
(
$blog_tag
);
return
[
'message'
=>
'success'
];
}
}
app/Http/Controllers/Api/V1/BlogsController.php
0 → 100755
View file @
82677a91
<?php
namespace
App\Http\Controllers\Api\V1
;
use
App\Http\Resources\BlogsResource
;
use
App\Models\Blogs\Blog
;
use
App\Repositories\Backend\Blogs\BlogsRepository
;
use
Illuminate\Http\Request
;
use
Validator
;
class
BlogsController
extends
APIController
{
protected
$repository
;
/**
* __construct.
*
* @param $repository
*/
public
function
__construct
(
BlogsRepository
$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
BlogsResource
::
collection
(
$this
->
repository
->
getForDataTable
()
->
paginate
(
$limit
)
);
}
/**
* Return the specified resource.
*
* @param User $user
*
* @return \Illuminate\Http\Response
*/
public
function
show
(
Blog
$blog
)
{
return
new
BlogsResource
(
$blog
);
}
/**
* Creates the Resource for Blog.
*
* @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
BlogsResource
(
Blog
::
orderBy
(
'created_at'
,
'desc'
)
->
first
());
}
/**
* @param Blog $blog
* @param UpdateBlogRequest $request
*
* @return mixed
*/
public
function
update
(
Request
$request
,
Blog
$blog
)
{
$validation
=
$this
->
validatingRequest
(
$request
,
'update'
);
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
());
}
$this
->
repository
->
update
(
$blog
,
$request
->
all
());
$blog
=
Blog
::
findOrfail
(
$blog
->
id
);
return
new
BlogsResource
(
$blog
);
}
public
function
validatingRequest
(
Request
$request
,
$type
=
"insert"
)
{
$featured_image
=
(
$type
==
"insert"
)
?
"required"
:
""
;
$validation
=
Validator
::
make
(
$request
->
all
(),
[
'name'
=>
'required|max:191'
,
'featured_image'
=>
$featured_image
,
'content'
=>
'required'
,
'categories'
=>
'required'
,
'tags'
=>
'required'
,
]);
return
$validation
;
}
public
function
messages
()
{
return
[
'name.required'
=>
'Please insert Blog Title'
,
'name.max'
=>
'Blog Title may not be greater than 191 characters.'
,
];
}
/**
* @param Blog $blog
* @param DeleteBlogRequest $request
*
* @return mixed
*/
public
function
destroy
(
Blog
$blog
,
Request
$request
)
{
$this
->
repository
->
delete
(
$blog
);
return
[
'message'
=>
'success'
];
}
}
app/Http/Resources/BlogTagsResource.php
0 → 100644
View file @
82677a91
<?php
namespace
App\Http\Resources
;
use
Illuminate\Http\Resources\Json\Resource
;
class
BlogTagsResource
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
,
];
}
}
app/Http/Resources/BlogsResource.php
0 → 100644
View file @
82677a91
<?php
namespace
App\Http\Resources
;
use
Illuminate\Http\Resources\Json\Resource
;
class
BlogsResource
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
,
'publish_datetime'
=>
$this
->
publish_datetime
->
format
(
'd/m/Y h:i A'
),
'status'
=>
$this
->
status
,
'created_at'
=>
optional
(
$this
->
created_at
)
->
toDateString
(),
'created_by'
=>
(
is_null
(
$this
->
user_name
))
?
optional
(
$this
->
owner
)
->
first_name
:
$this
->
user_name
,
];
}
}
routes/api.php
View file @
82677a91
...
@@ -48,5 +48,11 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
...
@@ -48,5 +48,11 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
// Blog Categories
// Blog Categories
Route
::
resource
(
'blog_categories'
,
'BlogCategoriesController'
);
Route
::
resource
(
'blog_categories'
,
'BlogCategoriesController'
);
// Blog Tags
Route
::
resource
(
'blog_tags'
,
'BlogTagsController'
);
// Blogs
Route
::
resource
(
'blogs'
,
'BlogsController'
);
});
});
});
});
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