优化分类和标签的快捷添加

This commit is contained in:
augushong
2021-06-30 12:43:26 +08:00
parent c089c972d3
commit c3f3d53752
3 changed files with 16 additions and 14 deletions

View File

@@ -54,15 +54,17 @@ class Tag extends Common
$post_data = $request->post();
$type = $post_data['type'];
$arr = explode(' ',$post_data['tags']);
$arr = array_unique(array_filter($arr));
foreach ($arr as $tag) {
$model_tag = ModelTag::where('title',$tag)->find();
$model_tag = ModelTag::where('title',$tag)->where('type',$type)->find();
if(empty($model_tag)){
ModelTag::create(['title'=>$tag]);
ModelTag::create(['title'=>$tag,'type'=>$type]);
}
}