CategoryLabelItem.php 1.8 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 模型层:标签明细 模型类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Models\Category
 * @package  App\Models\Category
 * @author    Richer <yangzi1028@163.com>
 * @date      2023年4月21日17:26:21
 * @copyright 2014-2023 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Models\Category;

use App\Models\BaseModel;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Class CategoryLabelItem
 * @property mixed name
 * @property mixed icon
 * @property mixed body
 * @property mixed description
 * @package App\Models
 */
class CategoryLabelItem extends BaseModel
{
    // 指定数据库表
    const TABLE = 'category_label_items';
    protected $table = self::TABLE ;

    // 指定对象显示名称:方便系统统一查询和做其他处理
    const OBJ_NAME = 'label-item';
    const OBJ_NAME_ZH = '标签明细';

    /**
     * @return BelongsTo
     */
    public function label(): BelongsTo
    {
        return $this->belongsTo(CategoryLabel::class, 'label_id');
    }

    /**
     * @param $value
     */
    public function setIconAttribute($value)
    {
        // 需要判断前端传来的路径是否是全路径,如果是全路径需要截取为相对路径
        $this->attributes['icon'] = substr_file_path($value);
    }

    /**
     * @param string $value 值
     *
     * @return array
     * @throws GuzzleException
     */
    public function getIconAttribute($value)
    {
        return splice_file_path($value);
    }
}