lyre/facet
Lyre Facet
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 asBlog Category,Task Categories, orSubscription Plan CategoryFacetValue: a concrete value inside a facet, such asFreeorMainFacetedEntity: 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 tablefacetValues()has-many-through relation to attached valuesattachFacetValues($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
FacetusesslugasID_COLUMNFacetValueusesslugasID_COLUMN- both expose lightweight computed fields such as
parent_nameandfacet_name - hierarchy endpoints return nested arrays with a
depthfield
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
Freetask flow - subscription plan categories, including the
Mainplan flow
Good examples to inspect:
app/Models/Assessment.phpapp/Models/Exam.phpdatabase/seeders/FacetSeeder.phpdatabase/seeders/TaskSeeder.phpapp/Filament/Resources/AssessmentResource.phpapp/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
facetValuesrelation - hierarchy support is implemented only where the repository explicitly uses
HasHierarchy
Related Packages
A package for simplifying the integration of a maker-checker approval process to...
Version History
| Version | Released | PHP | License |
|---|---|---|---|
| 1.5.0 | ^8.3 | MIT | |
| 1.4.3 | ^8.3 | MIT | |
| 1.4.2 | ^8.3 | MIT | |
| 1.4.1 | ^8.3 | MIT | |
| 1.4.0 | ^8.2 | MIT | |
| 1.3.2 | ^8.2 | MIT | |
| 1.3.1 | ^8.2 | MIT | |
| 1.3.0 | ^8.2 | MIT | |
| 1.2.1 | ^8.2 | MIT | |
| 1.2.0 | ^8.2 | MIT | |
| 1.1.0 | ^8.2 | MIT | |
| 1.0.11 | ^8.2 | MIT | |
| 1.0.10 | ^8.2 | MIT | |
| 1.0.9 | ^8.2 | MIT | |
| 1.0.8 | ^8.2 | MIT | |
| 1.0.7 | ^8.2 | MIT | |
| 1.0.6 | ^8.2 | MIT | |
| 1.0.5 | ^8.2 | MIT | |
| 1.0.4 | ^8.2 | MIT | |
| 1.0.3 | ^8.2 | MIT | |
| 1.0.2 | ^8.2 | MIT | |
| 1.0.1 | ^8.2 | MIT | |
| 1.0.0 | ^8.2 | MIT |