承接 davidwesdijk/laravel-polymorphic-eav 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

davidwesdijk/laravel-polymorphic-eav

Composer 安装命令:

composer require davidwesdijk/laravel-polymorphic-eav

包简介

Integrate the entity-attribute-value model with polymorphic Eloquent-relations in your Laravel application.

README 文档

README

Latest Version on Packagist Total Downloads

Integrate the entity-attribute-value model with polymorphic Eloquent-relations in your Laravel application.

Installation

You can install the package via composer:

composer require davidwesdijk/laravel-polymorphic-eav

Usage

Preparing your models

In order to implement the Entity-Attribute-Value-model to your Eloquent models, the only required action is to add the HasEntityAttributeValues Trait. That's all action required to use the full features this package brings.

use DavidWesdijk\LaravelPolymorphicEav\Traits\HasEntityAttributeValues;

class Product extends Model
{
     use HasEntityAttributeValues;

    // Implementation of your Eloquent model
}

Assigning attributes

Attributes are, when the Trait is added, accessable and assignable by the props accessor on your Eloquent Model. Just set its value!

class ProductController extends Controller
{
    public function update(AnyValidatedRequest $request, Product $product)
    {
        $product->props->details->color = $request->color; // E.g. 'red'

        // That's it!
    }
}

Accessing attributes

The assigned attributes are simply accessible by defining the group and the attribute in the props accessor like the following example. The concept is that all required properties must be accessible, without throwing exceptions, to keep you code clean, readable and maintainable.

// This attribute has been set before
$product->props->details->color; // 'red'

// This attribute has never been set before 
$product->props->details->sku; // null

// Even if the group has never been defined 
$product->props->foo->bar; // null

Other functionality

If you'd like e.g. remove a property you can either set it's value to null, or you can simply unset the value. The database entry will be removed.

unset($product->props->details->color);

$product->props->details->color; // null

Serializing

You might run into a situation where you have to have all assigned properties available in an array or json. This package respects the Arrayable and Jsonable interfaces.

$product->props->details->toArray(); ['color' => 'red']
$product->props->details->toJson(); '{color: "red"}'

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email david@favor.media instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固