lyre/facet 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lyre/facet

最新稳定版本:1.4.2

Composer 安装命令:

composer require lyre/facet

包简介

Simple categorization module for complex relationships

README 文档

README

Lyre Facet is a lyre/lyre add-on for tagging and organizing records with reusable facets and facet values.

It provides three core models:

  • Facet: the taxonomy group, such as Blog Category, Task Categories, or Subscription Plan Category
  • FacetValue: a concrete value inside a facet, such as Free or Main
  • FacetedEntity: the polymorphic pivot that links any facetable model to a facet value

How It Works

Tagging models

Any model can become facetable by using Lyre\Facet\Concerns\HasFacet.

That trait adds:

  • facetedEntities() morph-many relation to the pivot table
  • facetValues() has-many-through relation to attached values
  • attachFacetValues($ids) helper to replace all current facet assignments

This is how Aspire tags exams, assessments, tasks, subscription plans, and articles.

Hierarchies

Both Facet and FacetValue support optional parent/child hierarchy through parent_id.

The package exposes:

  • parent()
  • children()
  • ancestors()
  • descendants()
  • roots() scope

Repositories for Facet and FacetValue use HasHierarchy, which powers:

  • GET /api/facets/hierarchy/{facetId?}
  • GET /api/facetvalues/hierarchy/{facetValueId?}

facetvalues/hierarchy also accepts a facet query parameter so clients can scope root values to a specific facet.

Resource behavior

  • Facet uses slug as ID_COLUMN
  • FacetValue uses slug as ID_COLUMN
  • both expose lightweight computed fields such as parent_name and facet_name
  • hierarchy endpoints return nested arrays with a depth field

Installation

composer require lyre/facet

Publish assets:

php artisan vendor:publish --provider="Lyre\Facet\Providers\LyreFacetServiceProvider"

If you use Filament, register the plugin:

use Lyre\Facet\Filament\Plugins\LyreFacetFilamentPlugin;

$panel->plugins([
    new LyreFacetFilamentPlugin(),
]);

Example Usage

Add the trait to a model:

use Lyre\Facet\Concerns\HasFacet;

class Article extends Model
{
    use HasFacet;
}

Attach facet values:

$article->attachFacetValues([$newsId, $featuredId]);

Query tagged models through normal Lyre relation filters:

GET /api/articles?relation=facetValues,featured

Or scope dynamic section data in lyre/content using the facet filter, which resolves all values under a named facet and constrains the target model to those values.

Aspire Usage Notes

In Aspire, the package is used for:

  • blog article categories
  • exam categories
  • task categories, including the Free task flow
  • subscription plan categories, including the Main plan flow

Good examples to inspect:

  • app/Models/Assessment.php
  • app/Models/Exam.php
  • database/seeders/FacetSeeder.php
  • database/seeders/TaskSeeder.php
  • app/Filament/Resources/AssessmentResource.php
  • app/Filament/Resources/ExamResource.php

Limits To Keep In Mind

  • attachFacetValues() is a replace-all helper, not an additive sync helper
  • facet-based filtering depends on models exposing the facetValues relation
  • hierarchy support is implemented only where the repository explicitly uses HasHierarchy

统计信息

  • 总下载量: 294
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固