Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
lightCMS
提交
92f2ade5
L
lightCMS
项目概览
OpenDocCN
/
lightCMS
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
lightCMS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
92f2ade5
编写于
10月 24, 2019
作者:
E
eddy8
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve: get tags from content_tags
上级
435c9e69
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
28 addition
and
2 deletion
+28
-2
app/Http/Controllers/Admin/TagController.php
app/Http/Controllers/Admin/TagController.php
+8
-0
app/Repository/Admin/ContentRepository.php
app/Repository/Admin/ContentRepository.php
+17
-0
resources/views/admin/content/add.blade.php
resources/views/admin/content/add.blade.php
+3
-2
未找到文件。
app/Http/Controllers/Admin/TagController.php
浏览文件 @
92f2ade5
...
@@ -12,6 +12,8 @@ use Illuminate\Database\QueryException;
...
@@ -12,6 +12,8 @@ use Illuminate\Database\QueryException;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Str
;
use
Illuminate\Support\Str
;
use
Illuminate\View\View
;
use
Illuminate\View\View
;
use
App\Model\Admin\ContentTag
;
use
Illuminate\Support\Facades\DB
;
class
TagController
extends
Controller
class
TagController
extends
Controller
{
{
...
@@ -132,13 +134,19 @@ class TagController extends Controller
...
@@ -132,13 +134,19 @@ class TagController extends Controller
public
function
delete
(
$id
)
public
function
delete
(
$id
)
{
{
try
{
try
{
DB
::
beginTransaction
();
TagRepository
::
delete
(
$id
);
TagRepository
::
delete
(
$id
);
ContentTag
::
where
(
'tag_id'
,
$id
)
->
delete
();
DB
::
commit
();
return
[
return
[
'code'
=>
0
,
'code'
=>
0
,
'msg'
=>
'删除成功'
,
'msg'
=>
'删除成功'
,
'redirect'
=>
route
(
'admin::tag.index'
)
'redirect'
=>
route
(
'admin::tag.index'
)
];
];
}
catch
(
\
RuntimeException
$e
)
{
}
catch
(
\
RuntimeException
$e
)
{
DB
::
rollBack
();
return
[
return
[
'code'
=>
1
,
'code'
=>
1
,
'msg'
=>
'删除失败:'
.
$e
->
getMessage
(),
'msg'
=>
'删除失败:'
.
$e
->
getMessage
(),
...
...
app/Repository/Admin/ContentRepository.php
浏览文件 @
92f2ade5
...
@@ -6,8 +6,13 @@
...
@@ -6,8 +6,13 @@
namespace
App\Repository\Admin
;
namespace
App\Repository\Admin
;
use
App\Model\Admin\Content
;
use
App\Model\Admin\Content
;
use
App\Model\Admin\ContentTag
;
use
App\Repository\Searchable
;
use
App\Repository\Searchable
;
/**
* 使用当前类时必须先调用 setTable 方法设置所要操作的数据库表
* @package App\Repository\Admin
*/
class
ContentRepository
class
ContentRepository
{
{
use
Searchable
;
use
Searchable
;
...
@@ -103,4 +108,16 @@ class ContentRepository
...
@@ -103,4 +108,16 @@ class ContentRepository
->
orderBy
(
'id'
,
'desc'
)
->
orderBy
(
'id'
,
'desc'
)
->
paginate
(
$perPage
);
->
paginate
(
$perPage
);
}
}
public
static
function
tags
(
$entityId
,
$contentId
)
{
return
ContentTag
::
query
()
->
where
(
'entity_id'
,
$entityId
)
->
where
(
'content_id'
,
$contentId
)
->
leftJoin
(
'tags'
,
'tags.id'
,
'='
,
'content_tags.tag_id'
)
->
get
([
'name'
,
'tag_id'
]);
}
public
static
function
tagNames
(
$entityId
,
$contentId
)
{
return
self
::
tags
(
$entityId
,
$contentId
)
->
implode
(
'name'
,
','
);
}
}
}
resources/views/admin/content/add.blade.php
浏览文件 @
92f2ade5
...
@@ -439,7 +439,7 @@
...
@@ -439,7 +439,7 @@
<
div
class
=
"layui-form-item"
>
<
div
class
=
"layui-form-item"
>
<
label
class
=
"layui-form-label"
>
{{
$field
->
form_name
}}
</
label
>
<
label
class
=
"layui-form-label"
>
{{
$field
->
form_name
}}
</
label
>
<
div
class
=
"layui-input-block"
style
=
""
>
<
div
class
=
"layui-input-block"
style
=
""
>
<
input
name
=
"{{
$field->name
}}"
placeholder
=
"输入标签,按回车键或TAB键可新增标签"
value
=
"@if(isset(
$model
)) {{
$model
->
{
$field
->
name
}
}} @endif"
disabled
>
<
input
name
=
"{{
$field->name
}}"
placeholder
=
"输入标签,按回车键或TAB键可新增标签"
value
=
"@if(isset(
$model
)) {{
\App\Repository\Admin\ContentRepository::tagNames(
$entity
,
$model->id
) }} @endif"
>
</
div
>
</
div
>
</
div
>
</
div
>
<
script
>
<
script
>
...
@@ -459,7 +459,8 @@
...
@@ -459,7 +459,8 @@
// on character(s) added/removed (user is typing/deleting)
// on character(s) added/removed (user is typing/deleting)
function
onInput
(
e
){
function
onInput
(
e
){
var
value
=
e
.
detail
.
value
;
var
value
=
e
.
detail
.
value
;
tagify
.
settings
.
whitelist
.
length
=
0
;
tagify
.
settings
.
whitelist
=
[];
tagify
.
dropdown
.
hide
.
call
(
tagify
);
$
.
ajax
({
$
.
ajax
({
url
:
"{{ route('admin::tag.list') }}"
+
"?page=1&limit=50"
+
"&name="
+
value
,
url
:
"{{ route('admin::tag.list') }}"
+
"?page=1&limit=50"
+
"&name="
+
value
,
method
:
"GET"
,
method
:
"GET"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录