提交 92f2ade5 编写于 作者: E eddy8

improve: get tags from content_tags

上级 435c9e69
......@@ -12,6 +12,8 @@ use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Illuminate\View\View;
use App\Model\Admin\ContentTag;
use Illuminate\Support\Facades\DB;
class TagController extends Controller
{
......@@ -132,13 +134,19 @@ class TagController extends Controller
public function delete($id)
{
try {
DB::beginTransaction();
TagRepository::delete($id);
ContentTag::where('tag_id', $id)->delete();
DB::commit();
return [
'code' => 0,
'msg' => '删除成功',
'redirect' => route('admin::tag.index')
];
} catch (\RuntimeException $e) {
DB::rollBack();
return [
'code' => 1,
'msg' => '删除失败:' . $e->getMessage(),
......
......@@ -6,8 +6,13 @@
namespace App\Repository\Admin;
use App\Model\Admin\Content;
use App\Model\Admin\ContentTag;
use App\Repository\Searchable;
/**
* 使用当前类时必须先调用 setTable 方法设置所要操作的数据库表
* @package App\Repository\Admin
*/
class ContentRepository
{
use Searchable;
......@@ -103,4 +108,16 @@ class ContentRepository
->orderBy('id', 'desc')
->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', ',');
}
}
......@@ -439,7 +439,7 @@
<div class="layui-form-item">
<label class="layui-form-label">{{ $field->form_name }}</label>
<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>
<script>
......@@ -459,7 +459,8 @@
// on character(s) added/removed (user is typing/deleting)
function onInput(e){
var value = e.detail.value;
tagify.settings.whitelist.length = 0;
tagify.settings.whitelist = [];
tagify.dropdown.hide.call(tagify);
$.ajax({
url: "{{ route('admin::tag.list') }}" + "?page=1&limit=50" + "&name=" + value,
method: "GET",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册