misaf/vendra-attribute
Composer 安装命令:
composer require misaf/vendra-attribute
包简介
Reusable tenant-aware attributes and polymorphic values for Vendra models
README 文档
README
Reusable, tenant-agnostic attributes and polymorphic values for Vendra applications.
Features
- Reusable attribute definitions with optional units
- Polymorphic values that can belong to products or any other Eloquent model
- Automatic tenant scoping through
misaf/vendra-supportwhen a tenant resolver is available - Global operation when tenancy is not installed or enabled
- Sortable attributes and values
- Soft deletes
- Filament resource on configured panels
- English, German, and Persian translations
Requirements
- PHP 8.3+
- Laravel 13
- Filament 5
misaf/vendra-support
Installation
composer require misaf/vendra-attribute php artisan vendor:publish --tag=vendra-attribute-migrations php artisan migrate
Optional configuration and translations:
php artisan vendor:publish --tag=vendra-attribute-config php artisan vendor:publish --tag=vendra-attribute-translations
The service provider and Filament plugin are auto-registered.
When misaf/vendra-product is also installed by the host application, its
attribute fields are enabled automatically through the shared Vendra Support
resolver. Neither package requires the other directly.
Usage
Add attribute values to an Eloquent model with the provided concern:
use Illuminate\Database\Eloquent\Model; use Misaf\VendraAttribute\Concerns\HasAttributeValues; final class Product extends Model { use HasAttributeValues; }
Alternatively, a model may extend Misaf\VendraAttribute\Models\AttributableModel.
Create an attribute definition:
use Misaf\VendraAttribute\Models\Attribute; $weight = Attribute::query()->create([ 'name' => 'Weight', 'description' => 'Shipping weight', 'unit' => 'kg', 'status' => true, ]);
Assign a value to any attributable model:
$product->attributeValues()->create([ 'attribute_id' => $weight->id, 'value' => '1.2', ]);
Load values with their definitions:
$product->load('attributeValues.attribute'); foreach ($product->attributeValues as $attributeValue) { $name = $attributeValue->attribute->name; $value = $attributeValue->value; $unit = $attributeValue->attribute->unit; }
Tenant Awareness
The package never depends on a concrete tenant provider. Both Attribute and AttributeValue use the resolver-driven tenancy support from misaf/vendra-support.
- With the default null resolver, records are global and the migrations omit
tenant_id. - When a tenant provider binds an available resolver, migrations add
tenant_id, and models are scoped and stamped automatically.
Do not assign tenant_id manually.
Filament
Attribute definitions are managed in the Attributes cluster. By default, the plugin is registered on the admin panel.
Configure panels, the navigation group, and available units in config/vendra-attribute.php after publishing the configuration.
Seeding Permissions
php artisan vendra-attribute:seed
When tenancy is enabled, an optional tenant ID or slug may be supplied:
php artisan vendra-attribute:seed tenant-slug
Testing and Analysis
composer test
composer analyse
License
MIT.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-10