Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
P
Project_Laravel
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
TTS Nguyen Huu Huan
Project_Laravel
Commits
28c31dc7
Commit
28c31dc7
authored
Sep 13, 2022
by
TTS Nguyen Huu Huan
Committed by
20194288-huannh
Sep 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use uniform, validation library, tags input, ckeditor to post form
parent
925ac8d2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1556 additions
and
1480 deletions
+1556
-1480
PostController.php
app/Http/Controllers/PostController.php
+7
-1
Post.php
app/Models/Post.php
+3
-0
index.blade.php
resources/views/home/index.blade.php
+1463
-1449
head.blade.php
resources/views/partials/head.blade.php
+4
-2
form.blade.php
resources/views/post/form.blade.php
+77
-26
web.php
routes/web.php
+2
-2
No files found.
app/Http/Controllers/PostController.php
View file @
28c31dc7
...
@@ -34,7 +34,10 @@ public function store(Request $request) {
...
@@ -34,7 +34,10 @@ public function store(Request $request) {
]);
]);
$post
=
Post
::
create
(
$request
->
only
([
$post
=
Post
::
create
(
$request
->
only
([
'title'
,
'title'
,
'user_id'
'user_id'
,
'keywords'
,
'description'
,
'content'
]));
]));
$post
->
categories
()
->
sync
(
$request
->
category_ids
);
$post
->
categories
()
->
sync
(
$request
->
category_ids
);
return
redirect
()
->
route
(
'posts.index'
)
->
with
(
'message'
,
'Tạo mới thành công'
);
return
redirect
()
->
route
(
'posts.index'
)
->
with
(
'message'
,
'Tạo mới thành công'
);
...
@@ -46,6 +49,9 @@ public function edit(Post $post, Request $request) {
...
@@ -46,6 +49,9 @@ public function edit(Post $post, Request $request) {
public
function
update
(
Post
$post
,
Request
$request
)
{
public
function
update
(
Post
$post
,
Request
$request
)
{
$post
->
update
(
$request
->
only
([
$post
->
update
(
$request
->
only
([
'title'
,
'title'
,
'keywords'
,
'description'
,
'content'
]));
]));
$post
->
categories
()
->
sync
(
$request
->
category_ids
);
$post
->
categories
()
->
sync
(
$request
->
category_ids
);
return
redirect
()
->
route
(
'posts.index'
)
->
with
(
'message'
,
'Cập nhật thành công'
);
return
redirect
()
->
route
(
'posts.index'
)
->
with
(
'message'
,
'Cập nhật thành công'
);
...
...
app/Models/Post.php
View file @
28c31dc7
...
@@ -15,6 +15,9 @@ class Post extends Model
...
@@ -15,6 +15,9 @@ class Post extends Model
'view_count'
=>
'integer'
,
'view_count'
=>
'integer'
,
'status'
=>
'integer'
,
'status'
=>
'integer'
,
];
];
protected
$attributes
=
[
'status'
=>
true
,
];
public
function
user
()
{
public
function
user
()
{
return
$this
->
belongsTo
(
User
::
class
);
return
$this
->
belongsTo
(
User
::
class
);
}
}
...
...
resources/views/home/index.blade.php
View file @
28c31dc7
This source diff could not be displayed because it is too large. You can
view the blob
instead.
resources/views/partials/head.blade.php
View file @
28c31dc7
...
@@ -22,6 +22,9 @@
...
@@ -22,6 +22,9 @@
<!-- /core JS files -->
<!-- /core JS files -->
<!-- Theme JS files -->
<!-- Theme JS files -->
<script
src=
"/global_assets/js/demo_pages/editor_ckeditor.js"
></script>
<script
src=
"/global_assets/js/plugins/editors/ckeditor/ckeditor.js"
></script>
<script
src=
"/global_assets/js/plugins/forms/styling/uniform.min.js"
></script>
<script
src=
"/global_assets/js/plugins/forms/validation/validate.min.js"
></script>
<script
src=
"/global_assets/js/plugins/forms/validation/validate.min.js"
></script>
<script
src=
"/global_assets/js/plugins/forms/selects/select2.min.js"
></script>
<script
src=
"/global_assets/js/plugins/forms/selects/select2.min.js"
></script>
<script
src=
"/global_assets/js/plugins/visualization/d3/d3.min.js"
></script>
<script
src=
"/global_assets/js/plugins/visualization/d3/d3.min.js"
></script>
...
@@ -32,8 +35,7 @@
...
@@ -32,8 +35,7 @@
<script
src=
"/global_assets/js/plugins/ui/moment/moment.min.js"
></script>
<script
src=
"/global_assets/js/plugins/ui/moment/moment.min.js"
></script>
<script
src=
"/global_assets/js/plugins/pickers/daterangepicker.js"
></script>
<script
src=
"/global_assets/js/plugins/pickers/daterangepicker.js"
></script>
<script
src=
"/global_assets/js/plugins/ui/perfect_scrollbar.min.js"
></script>
<script
src=
"/global_assets/js/plugins/ui/perfect_scrollbar.min.js"
></script>
<script
src=
"/global_assets/js/plugins/forms/tags/tagsinput.min.js"
></script>
<script
src=
"/assets/js/app.js"
></script>
<script
src=
"/assets/js/app.js"
></script>
<script
src=
"/global_assets/js/demo_pages/dashboard.js"
></script>
<script
src=
"/global_assets/js/demo_pages/layout_fixed_sidebar_custom.js"
></script>
<!-- /theme JS files -->
<!-- /theme JS files -->
resources/views/post/form.blade.php
View file @
28c31dc7
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
<
div
class
=
"page-title d-flex"
>
<
div
class
=
"page-title d-flex"
>
<
h4
>
<
h4
>
<
i
class
=
"icon-arrow-left52 mr-2"
></
i
>
<
span
class
=
"font-weight-semibold"
>
Bài
viết
</
span
>
-
<
i
class
=
"icon-arrow-left52 mr-2"
></
i
>
<
span
class
=
"font-weight-semibold"
>
Bài
viết
</
span
>
-
@
if
(
isset
(
$post
)
)
@
if
(
$post
->
id
)
Sửa
Sửa
@
else
@
else
Thêm
mới
Thêm
mới
...
@@ -45,39 +45,46 @@
...
@@ -45,39 +45,46 @@
<
div
class
=
"card"
>
<
div
class
=
"card"
>
<
div
class
=
"card-body"
>
<
div
class
=
"card-body"
>
<
div
class
=
"form-group row"
>
<
div
class
=
"form-group row"
>
<
label
class
=
"col-lg-3 col-form-label"
>
Tiêu
đề
</
label
>
<
label
class
=
"col-lg-3 col-form-label"
>
Tiêu
đề
<
span
class
=
"text-danger"
>*</
span
>
</
label
>
<
div
class
=
"col-lg-9"
>
<
div
class
=
"col-lg-9"
>
<
input
type
=
"text"
class
=
"form-control"
value
=
"{{
isset(
$post
)
?
$post->title
: ''}}"
placeholder
=
"Tiêu đề"
name
=
"title"
>
<
input
type
=
"text"
class
=
"form-control"
value
=
"{{
$post->id
?
$post->title
: ''}}"
placeholder
=
"Tiêu đề"
name
=
"title"
>
</
div
>
</
div
>
</
div
>
</
div
>
<
div
class
=
"form-group row"
>
<
div
class
=
"form-group row"
>
<
label
class
=
"col-lg-3 col-form-label"
>
Ảnh
:
</
label
>
<
label
class
=
"col-lg-3 col-form-label"
>
Ảnh
</
label
>
<
div
class
=
"col-lg-9"
>
<
div
class
=
"col-lg-9"
>
<
input
type
=
"file"
class
=
"form-control"
name
=
"image"
>
<
input
type
=
"file"
class
=
"form-control
form-input-styled
"
name
=
"image"
>
</
div
>
</
div
>
</
div
>
</
div
>
<
div
class
=
"form-group row"
>
<
div
class
=
"form-group row"
>
<
label
class
=
"col-lg-3 col-form-label"
>
Mô
tả
:
</
label
>
<
label
class
=
"col-lg-3 col-form-label"
>
Từ
khóa
<
span
class
=
"text-danger"
>*</
span
>
</
label
>
<
div
class
=
"col-lg-9"
>
<
div
class
=
"col-lg-9"
>
<
input
type
=
"text"
class
=
"form-control"
name
=
"description
"
>
<
input
type
=
"text"
data
-
role
=
"tagsinput"
class
=
"form-control tagsinput"
name
=
"keywords"
value
=
"{{
$post->id
?
$post->keywords
: ''}}
"
>
</
div
>
</
div
>
</
div
>
</
div
>
<
div
class
=
"form-group row"
>
<
div
class
=
"form-group row"
>
<
label
class
=
"col-lg-3 col-form-label"
>
Trạng
thái
:</
label
>
<
label
class
=
"col-lg-3 col-form-label"
>
Mô
tả
<
span
class
=
"text-danger"
>*</
span
></
label
>
<
div
class
=
"col-lg-9"
>
<
input
type
=
"text"
class
=
"form-control"
name
=
"description"
value
=
"{{
$post->id
?
$post->description
: ''}}"
>
</
div
>
</
div
>
<
div
class
=
"form-group row"
>
<
label
class
=
"col-lg-3 col-form-label"
>
Trạng
thái
</
label
>
<
div
class
=
"col-lg-9"
>
<
div
class
=
"col-lg-9"
>
<
div
class
=
"form-check form-check-inline"
>
<
div
class
=
"form-check form-check-inline"
>
<
label
class
=
"form-check-label"
>
<
label
class
=
"form-check-label"
>
<
input
type
=
"radio"
class
=
"form-
check-input"
name
=
"status"
checked
type
=
"checkbox"
>
<
input
type
=
"radio"
class
=
"form-
input-styled"
name
=
"status"
{{
$post
->
status
?
''
:
'checked'
}}
type
=
"checkbox"
>
Ẩn
Ẩn
</
label
>
</
label
>
</
div
>
</
div
>
<
div
class
=
"form-check form-check-inline"
>
<
div
class
=
"form-check form-check-inline"
>
<
label
class
=
"form-check-label"
>
<
label
class
=
"form-check-label"
>
<
input
type
=
"radio"
class
=
"form-
check-input"
name
=
"status"
type
=
"checkbox"
>
<
input
type
=
"radio"
class
=
"form-
input-styled"
name
=
"status"
{{
$post
->
status
?
'checked'
:
''
}}
type
=
"checkbox"
>
Hiện
Hiện
</
label
>
</
label
>
</
div
>
</
div
>
...
@@ -85,14 +92,26 @@
...
@@ -85,14 +92,26 @@
</
div
>
</
div
>
<
div
class
=
"form-group row"
>
<
div
class
=
"form-group row"
>
<
label
class
=
"col-lg-3 col-form-label"
>
Nội
dung
:</
label
>
<
label
class
=
"col-lg-3 col-form-label"
>
Danh
mục
<
span
class
=
"text-danger"
>*</
span
></
label
>
<
div
class
=
"col-lg-9"
>
<
div
class
=
"col-lg-9"
>
<
textarea
class
=
"form-control"
id
=
"exampleFormControlTextarea1"
rows
=
"3"
name
=
"content"
></
textarea
>
<
select
class
=
"form-control select-multiple-drag select2 col-lg-9"
multiple
=
"multiple"
data
-
fouc
name
=
"category_ids[]"
>
</
div
>
@
foreach
(
$categories
as
$category
)
<
option
{{
in_array
(
$category
->
id
,
$post
->
categories
->
pluck
(
'id'
)
->
all
())
?
'selected'
:
''
}}
value
=
"
{
{$category->id}
}
"
>
{{
$category
->
title
}}
</
option
>
@
endforeach
</
select
>
</
div
>
</
div
>
<
div
class
=
"form-group row"
>
<
label
class
=
"col-lg-3 col-form-label"
>
Nội
dung
<
span
class
=
"text-danger"
>*</
span
></
label
>
</
div
>
<
div
class
=
"form-group row"
>
<
textarea
name
=
"content"
id
=
"content"
rows
=
"4"
cols
=
"4"
>
{{
$post
->
content
}}
</
textarea
>
</
div
>
</
div
>
<
div
class
=
"text-right"
>
<
div
class
=
"text-right"
>
<
button
type
=
""
class
=
"btn btn-primary"
>
Lưu
<
i
class
=
"icon-paperplane ml-2"
></
i
></
button
>
<
button
type
=
"
submit
"
class
=
"btn btn-primary"
>
Lưu
<
i
class
=
"icon-paperplane ml-2"
></
i
></
button
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
...
@@ -100,19 +119,57 @@
...
@@ -100,19 +119,57 @@
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
<!--
/
content
area
-->
</
form
>
</
form
>
<
script
>
<
script
>
$
(
function
(){
$
(
function
(){
if
(
!
$
()
.
validate
)
{
CKEDITOR
.
replace
(
'content'
,
{
console
.
warn
(
'Warning - validate.min.js is not loaded.'
);
height
:
400
,
return
;
extraPlugins
:
'forms'
}
}
)
$
(
'.select2'
)
.
select2
()
$
(
'.select2'
)
.
select2
()
$
(
'.form-input-styled'
)
.
uniform
()
$
(
'#form'
)
.
validate
({
$
(
'#form'
)
.
validate
({
ignore
:
'input[type=hidden], .select2-search__field'
,
// ignore hidden fields
errorClass
:
'validation-invalid-label'
,
successClass
:
'validation-valid-label'
,
validClass
:
'validation-valid-label'
,
highlight
:
function
(
element
,
errorClass
)
{
$
(
element
)
.
removeClass
(
errorClass
);
},
unhighlight
:
function
(
element
,
errorClass
)
{
$
(
element
)
.
removeClass
(
errorClass
);
},
success
:
function
(
label
)
{
label
.
addClass
(
'validation-valid-label'
)
},
// Different components require proper error label placement
errorPlacement
:
function
(
error
,
element
)
{
// Unstyled checkboxes, radios
if
(
element
.
parents
()
.
hasClass
(
'form-check'
))
{
error
.
appendTo
(
element
.
parents
(
'.form-check'
)
.
parent
()
);
}
// Input with icons and Select2
else
if
(
element
.
parents
()
.
hasClass
(
'form-group-feedback'
)
||
element
.
hasClass
(
'select2-hidden-accessible'
))
{
error
.
appendTo
(
element
.
parent
()
);
}
// Input group, styled file input
else
if
(
element
.
parent
()
.
is
(
'.uniform-uploader, .uniform-select'
)
||
element
.
parents
()
.
hasClass
(
'input-group'
))
{
error
.
appendTo
(
element
.
parent
()
.
parent
()
);
}
// Other elements
else
{
error
.
insertAfter
(
element
);
}
},
rules
:
{
rules
:
{
title
:
{
title
:
{
required
:
true
required
:
true
...
@@ -123,9 +180,6 @@
...
@@ -123,9 +180,6 @@
content
:
{
content
:
{
required
:
true
required
:
true
},
},
status
:
{
required
:
true
}
},
},
messages
:
{
messages
:
{
title
:
{
title
:
{
...
@@ -137,9 +191,6 @@
...
@@ -137,9 +191,6 @@
content
:
{
content
:
{
required
:
"Nội dung không được bỏ trống"
required
:
"Nội dung không được bỏ trống"
},
},
status
:
{
required
:
"Trường trạng thái là bắt buộc."
}
}
}
})
})
...
...
routes/web.php
View file @
28c31dc7
...
@@ -18,9 +18,9 @@
...
@@ -18,9 +18,9 @@
*/
*/
Auth
::
routes
();
Auth
::
routes
();
Route
::
middleware
([
'auth'
])
->
group
(
function
()
{
Route
::
middleware
([
'auth'
])
->
group
(
function
()
{
Route
::
resource
(
'posts'
,
PostController
::
class
);
Route
::
resource
(
'posts'
,
PostController
::
class
);
Route
::
prefix
(
'posts'
)
->
name
(
'posts.'
)
->
group
(
function
()
{
Route
::
prefix
(
'posts'
)
->
name
(
'posts.'
)
->
group
(
function
()
{
Route
::
post
(
'ajax'
,
[
PostController
::
class
,
'ajax'
])
->
name
(
'ajax'
);
Route
::
post
(
'ajax'
,
[
PostController
::
class
,
'ajax'
])
->
name
(
'ajax'
);
});
});
Route
::
get
(
'/'
,
[
App\Http\Controllers\HomeController
::
class
,
'index'
])
->
name
(
'home'
);
Route
::
get
(
'/'
,
[
App\Http\Controllers\HomeController
::
class
,
'index'
])
->
name
(
'home'
);
...
...
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