承接 stelianandrei/eloquent-custom-fields 相关项目开发

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

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

stelianandrei/eloquent-custom-fields

Composer 安装命令:

composer require stelianandrei/eloquent-custom-fields

包简介

Add any extra fields to your Eloquent models

README 文档

README

This package gives a basic way of attaching arbitrary fields to an Eloquent model. The Custom Fields are simply a collection of Eloquent models that are related to your own models via a MorphToMany relation.

Instalation

This package can be installed through Composer.

composer require stelianandrei/eloquent-custom-fields

Make sure you publish the required migration:

php artisan vendor:publish --provider="StelianAndrei\EloquentCustomFields\ServiceProvider" --tag="migrations"

Optionally, to publish the configuration:

php artisan vendor:publish --provider="StelianAndrei\EloquentCustomFields\ServiceProvider" --tag="config"

The CustomField model

The model is very simple, it has just two attributes:

  • label - (required) mainly used to identify the CustomField in a human-readable form
  • type - (optional) what the custom field represents. This can be used to determine how to deal with that field (eg. " text", "email", "textarea") or something else as a clue for data manipulation (eg. "json", "currency" , "lat_long").

If you need to add extra functionality to this model, just create a new model, extend the StelianAndrei\EloquentCustomFields\CustomField class and update the value for field_class in the config file ( make sure you publish it first, see above).

Usage

In order to allow your models to use this functionality, you need to use the HasCustomFields trait:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use StelianAndrei\EloquentCustomFields\HasCustomFields;

class MyModel extends Model
{
    use HasCustomFields;

    //
}

Create the fields as you would create any other model then associate it to your own models with the desired value.

use StelianAndrei\EloquentCustomFields\CustomField;

$firstName = CustomField::new(['label' => 'First Name']);
$lastName = CustomField::new(['label' => 'Last Name']);

$myModel->customFields()->attach($firstName, ['value' => 'John']);
$myModel->customFields()->attach($lastName, ['value' => 'Doe']);

Any other methods of creating or removing relations between models. should also work.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固