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
afa63fb5
Commit
afa63fb5
authored
Dec 07, 2017
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Blog Module
parent
eb880c0d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
104 deletions
+101
-104
BlogsController.php
app/Http/Controllers/Backend/Blogs/BlogsController.php
+34
-88
BlogsRepository.php
app/Repositories/Backend/Blogs/BlogsRepository.php
+59
-9
mix-manifest.json
public/mix-manifest.json
+7
-7
edit.blade.php
resources/views/backend/blogs/edit.blade.php
+1
-0
No files found.
app/Http/Controllers/Backend/Blogs/BlogsController.php
View file @
afa63fb5
...
...
@@ -16,6 +16,16 @@ use App\Repositories\Backend\Blogs\BlogsRepository;
*/
class
BlogsController
extends
Controller
{
/**
* Blog Status
*/
protected
$status
=
[
'Published'
=>
'Published'
,
'Draft'
=>
'Draft'
,
'Inactive'
=>
'Inactive'
,
'Scheduled'
=>
'Scheduled'
,
];
/**
* @var BlogsRepository
*/
...
...
@@ -36,14 +46,9 @@ class BlogsController extends Controller
*/
public
function
index
(
ManageBlogsRequest
$request
)
{
$status
=
[
'Published'
=>
'Published'
,
'Draft'
=>
'Draft'
,
'Inactive'
=>
'Inactive'
,
'Scheduled'
=>
'Scheduled'
,
];
return
view
(
'backend.blogs.index'
,
compact
(
'status'
));
return
view
(
'backend.blogs.index'
)
->
with
([
'status'
=>
$this
->
status
]);
}
/**
...
...
@@ -53,16 +58,14 @@ class BlogsController extends Controller
*/
public
function
create
(
ManageBlogsRequest
$request
)
{
$blogCategories
=
BlogCategory
::
where
(
'status'
,
1
)
->
pluck
(
'name'
,
'id'
);
$blogTags
=
BlogTag
::
where
(
'status'
,
1
)
->
pluck
(
'name'
,
'id'
);
$status
=
[
'Published'
=>
'Published'
,
'Draft'
=>
'Draft'
,
'Inactive'
=>
'Inactive'
,
'Scheduled'
=>
'Scheduled'
,
];
return
view
(
'backend.blogs.create'
,
compact
(
'blogCategories'
,
'blogTags'
,
'status'
));
$blogCategories
=
BlogCategory
::
getSelectData
();
$blogTags
=
BlogTag
::
getSelectData
();
return
view
(
'backend.blogs.create'
)
->
with
([
'blogCategories'
=>
$blogCategories
,
'blogTags'
=>
$blogTags
,
'status'
=>
$this
->
status
]);
}
/**
...
...
@@ -73,8 +76,7 @@ class BlogsController extends Controller
public
function
store
(
StoreBlogsRequest
$request
)
{
$input
=
$request
->
all
();
$tagsArray
=
$this
->
createTagsArray
(
$input
[
'tags'
]);
$categoriesArray
=
$this
->
createCategoriesArray
(
$input
[
'categories'
]);
$this
->
blogs
->
create
(
$input
,
$tagsArray
,
$categoriesArray
);
return
redirect
()
->
route
(
'admin.blogs.index'
)
->
withFlashSuccess
(
trans
(
'alerts.backend.blogs.created'
));
...
...
@@ -88,25 +90,20 @@ class BlogsController extends Controller
*/
public
function
edit
(
Blog
$blog
,
ManageBlogsRequest
$request
)
{
$blogCategories
=
BlogCategory
::
where
(
'status'
,
1
)
->
pluck
(
'name'
,
'id'
);
$blogTags
=
BlogTag
::
where
(
'status'
,
1
)
->
pluck
(
'name'
,
'id'
);
$status
=
[
'Published'
=>
'Published'
,
'Draft'
=>
'Draft'
,
'InActive'
=>
'InActive'
,
'Scheduled'
=>
'Scheduled'
,
];
$blogCategories
=
BlogCategory
::
getSelectData
();
$blogTags
=
BlogTag
::
getSelectData
();
$selectedCategories
=
$blog
->
categories
->
pluck
(
'id'
)
->
toArray
();
$selectedtags
=
$blog
->
tags
->
pluck
(
'id'
)
->
toArray
();
return
view
(
'backend.blogs.edit'
,
compact
(
'blogCategories'
,
'blogTags'
,
'status'
,
'selectedCategories'
,
'selectedtags'
)
)
->
withBlog
(
$blog
);
return
view
(
'backend.blogs.edit'
)
->
with
([
'blog'
=>
$blog
,
'blogCategories'
=>
$blogCategories
,
'blogTags'
=>
$blogTags
,
'selectedCategories'
=>
$selectedCategories
,
'selectedtags'
=>
$selectedtags
,
'status'
=>
$this
->
status
]
);
}
/**
...
...
@@ -118,10 +115,8 @@ class BlogsController extends Controller
public
function
update
(
Blog
$blog
,
UpdateBlogsRequest
$request
)
{
$input
=
$request
->
all
();
$tagsArray
=
$this
->
createTagsArray
(
$input
[
'tags'
]);
$categoriesArray
=
$this
->
createCategoriesArray
(
$input
[
'categories'
]);
$this
->
blogs
->
update
(
$blog
,
$input
,
$tagsArray
,
$categoriesArray
);
$this
->
blogs
->
update
(
$blog
,
$input
);
return
redirect
()
->
route
(
'admin.blogs.index'
)
->
withFlashSuccess
(
trans
(
'alerts.backend.blogs.updated'
));
}
...
...
@@ -138,53 +133,4 @@ class BlogsController extends Controller
return
redirect
()
->
route
(
'admin.blogs.index'
)
->
withFlashSuccess
(
trans
(
'alerts.backend.blogs.deleted'
));
}
/**
* Creating Tags Array.
*
* @param Array($tags)
*
* @return array
*/
public
function
createTagsArray
(
$tags
)
{
//Creating a new array for tags (newly created)
$tags_array
=
[];
foreach
(
$tags
as
$tag
)
{
if
(
is_numeric
(
$tag
))
{
$tags_array
[]
=
$tag
;
}
else
{
$newTag
=
BlogTag
::
create
([
'name'
=>
$tag
,
'status'
=>
1
,
'created_by'
=>
1
]);
$tags_array
[]
=
$newTag
->
id
;
}
}
return
$tags_array
;
}
/**
* Creating Tags Array.
*
* @param Array($tags)
*
* @return array
*/
public
function
createCategoriesArray
(
$categories
)
{
//Creating a new array for categories (newly created)
$categories_array
=
[];
foreach
(
$categories
as
$category
)
{
if
(
is_numeric
(
$category
))
{
$categories_array
[]
=
$category
;
}
else
{
$newCategory
=
BlogCategory
::
create
([
'name'
=>
$category
,
'status'
=>
1
,
'created_by'
=>
1
]);
$categories_array
[]
=
$newCategory
->
id
;
}
}
return
$categories_array
;
}
}
app/Repositories/Backend/Blogs/BlogsRepository.php
View file @
afa63fb5
...
...
@@ -44,16 +44,16 @@ class BlogsRepository extends BaseRepository
/**
* @param array $input
* @param array $tagsArray
* @param array $categoriesArray
*
* @throws GeneralException
*
* @return bool
*/
public
function
create
(
array
$input
,
array
$tagsArray
,
array
$categoriesArray
)
public
function
create
(
array
$input
)
{
// dd(Carbon::createFromFormat('d/m/Y h:i a',$input['publish_datetime']));
$tagsArray
=
$this
->
createTagsArray
(
$input
[
'tags'
]);
$categoriesArray
=
$this
->
createCategoriesArray
(
$input
[
'categories'
]);
DB
::
transaction
(
function
()
use
(
$input
,
$tagsArray
,
$categoriesArray
)
{
$blogs
=
self
::
MODEL
;
$blogs
=
new
$blogs
();
...
...
@@ -94,15 +94,16 @@ class BlogsRepository extends BaseRepository
}
/**
* Update Blog
*
* @param $blogs
* @param array $input
* @param array $tagsArray
* @param array $categoriesArray
*/
public
function
update
(
$blogs
,
array
$input
,
array
$tagsArray
,
array
$categoriesArray
)
public
function
update
(
$blogs
,
array
$input
)
{
// dd( Carbon::parse($input['publish_datetime']));
// dd($input['publish_datetime']);
$tagsArray
=
$this
->
createTagsArray
(
$input
[
'tags'
]);
$categoriesArray
=
$this
->
createCategoriesArray
(
$input
[
'categories'
]);
$blogs
->
name
=
$input
[
'name'
];
$blogs
->
slug
=
str_slug
(
$input
[
'name'
]);
$blogs
->
content
=
$input
[
'content'
];
...
...
@@ -145,6 +146,55 @@ class BlogsRepository extends BaseRepository
});
}
/**
* Creating Tags Array.
*
* @param Array($tags)
*
* @return array
*/
public
function
createTagsArray
(
$tags
)
{
//Creating a new array for tags (newly created)
$tags_array
=
[];
foreach
(
$tags
as
$tag
)
{
if
(
is_numeric
(
$tag
))
{
$tags_array
[]
=
$tag
;
}
else
{
$newTag
=
BlogTag
::
create
([
'name'
=>
$tag
,
'status'
=>
1
,
'created_by'
=>
1
]);
$tags_array
[]
=
$newTag
->
id
;
}
}
return
$tags_array
;
}
/**
* Creating Tags Array.
*
* @param Array($tags)
*
* @return array
*/
public
function
createCategoriesArray
(
$categories
)
{
//Creating a new array for categories (newly created)
$categories_array
=
[];
foreach
(
$categories
as
$category
)
{
if
(
is_numeric
(
$category
))
{
$categories_array
[]
=
$category
;
}
else
{
$newCategory
=
BlogCategory
::
create
([
'name'
=>
$category
,
'status'
=>
1
,
'created_by'
=>
1
]);
$categories_array
[]
=
$newCategory
->
id
;
}
}
return
$categories_array
;
}
/**
* @param Model $blog
*
...
...
public/mix-manifest.json
View file @
afa63fb5
{
"/js/frontend.js"
:
"/js/frontend.
f5faf334d6b2231b48c8
.js"
,
"/js/backend.js"
:
"/js/backend.
d106d5f7e2110ee3cea
7.js"
,
"/js/frontend.js"
:
"/js/frontend.
945469bbbc12df3ad9e1
.js"
,
"/js/backend.js"
:
"/js/backend.
79d9e4698dadbc0d93c
7.js"
,
"/mix.js"
:
"/mix.247ab120fe7680658924.js"
,
"/css/frontend.css"
:
"/css/frontend.
90a13bfbf8d4ea6a30a8eb218e8d48b3
.css"
,
"/css/backend.css"
:
"/css/backend.
7b6d826816293ff35f4185341567f559
.css"
,
"/css/backend-custom.css"
:
"/css/backend-custom.
187b92dacd8c501e4a19407d700d279b
.css"
,
"/js/backend-custom.js"
:
"/js/backend-custom.
3ee9346acb0cd5e1f3edf70e9117e1f4
.js"
,
"/js/dataTable.js"
:
"/js/dataTable.
0db0f52a09a62d485aa1229ed981b1cf
.js"
"/css/frontend.css"
:
"/css/frontend.
3af0a6cbd7d1d8d042f2a37e97008b7c
.css"
,
"/css/backend.css"
:
"/css/backend.
f8550f50504e5b8ef6055285205f223a
.css"
,
"/css/backend-custom.css"
:
"/css/backend-custom.
50f14193ab908e3cf471dea6cb6616ae
.css"
,
"/js/backend-custom.js"
:
"/js/backend-custom.
e6ea05e1824d0dd8e7c62027c135b7f2
.js"
,
"/js/dataTable.js"
:
"/js/dataTable.
f968d300a6a0b871f138f114361259c8
.js"
}
\ No newline at end of file
resources/views/backend/blogs/edit.blade.php
View file @
afa63fb5
...
...
@@ -10,6 +10,7 @@
@
endsection
@
section
(
'content'
)
{{
Form
::
model
(
$blog
,
[
'route'
=>
[
'admin.blogs.update'
,
$blog
],
'class'
=>
'form-horizontal'
,
'role'
=>
'form'
,
'method'
=>
'PATCH'
,
'id'
=>
'edit-role'
,
'files'
=>
true
])
}}
<
div
class
="
box
box
-
success
">
...
...
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