Files
2025-05-06 17:16:37 +08:00

64 lines
1.4 KiB
PHP

<?php
namespace plugin\admin\app\model;
use plugin\admin\app\model\Base;
/**
* @property integer $id 主键(主键)
* @property string $title 标题
* @property string $icon 图标
* @property string $key 标识
* @property integer $pid 上级菜单
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
* @property string $href url
* @property integer $type 类型
* @property integer $weight 排序
*/
class Rule extends Base
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'wa_rules';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* 获取翻译后的标题
* @param string $lang 语言代码
* @return string
*/
public function getTranslatedTitle($lang = null)
{
if (!$lang) {
$lang = session('lang', 'zh-cn');
}
$translatedTitle = RuleTranslation::getTranslatedTitle($this->id, $lang);
return $translatedTitle ?: $this->title;
}
/**
* 设置翻译标题
* @param string $lang 语言代码
* @param string $title 翻译标题
* @return bool
*/
public function setTranslatedTitle($lang, $title)
{
return RuleTranslation::updateOrCreate(
['rule_id' => $this->id, 'lang' => $lang],
['title' => $title]
);
}
}