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

improve: get tags from content_tags

上级 435c9e69
...@@ -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(),
......
...@@ -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', ',');
}
} }
...@@ -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.
先完成此消息的编辑!
想要评论请 注册