This commit is contained in:
2025-03-26 17:13:11 +08:00
parent 9f3bfacc2f
commit 6e79dd47c4
3 changed files with 134 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace app\controller;
use app\model\TagGroup;
use app\util\Util;
use support\Request;
class TagGroupController
{
// 列表
public function list(Request $request)
{
$list = TagGroup::with('tags')->get();
$languageArr = config('translation.fallback_locale');
$language = $request->user['language'];
foreach ($list as &$item) {
$item['names'] = unserialize($item['names']);
if(in_array($language, $languageArr)){
$item['name'] = $item['names'][$language];
}
foreach ($item['tags'] as &$tag) {
$tag['names'] = unserialize($tag['names']);
if(in_array($language, $languageArr)){
$item['name'] = $item['names'][$language];
}
}
}
return Util::success($list);
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace app\model;
use app\util\Util;
use config\constants\Constants;
use DateTimeInterface;
use Illuminate\Support\Carbon;
use support\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Tag extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'tag';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
//设置黑名单
protected $guarded = ['id','created_at','updated_at'];
// 指定日期字段存储格式为时间戳
protected $dateFormat = 'U';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
use SoftDeletes;
protected $dates = ['deleted_at'];
// 定义反向多对一关联
public function group()
{
return $this->belongsTo(TagGroup::class, 'group_id', 'id');
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace app\model;
use app\util\Util;
use config\constants\Constants;
use DateTimeInterface;
use Illuminate\Support\Carbon;
use support\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class TagGroup extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'tag_group';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
//设置黑名单
protected $guarded = ['id','created_at','updated_at'];
// 指定日期字段存储格式为时间戳
protected $dateFormat = 'U';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
use SoftDeletes;
protected $dates = ['deleted_at'];
// 定义与 Tag 的一对多关系
public function tags()
{
return $this->hasMany(Tag::class, 'group_id', 'id');
}
}