dottwatson/laravel-model-meta 问题修复 & 功能扩展

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

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

dottwatson/laravel-model-meta

Composer 安装命令:

composer require dottwatson/laravel-model-meta

包简介

A fast, configurable and smart tool to manage metat data on your models

README 文档

README

Extend your models with unlimited meta attributes

Build Status

Easly add meta data to your model, without change any logic. This package can gives you the ability to extend your laravel model with a configurable set of meta data. Each meta will be automatically inserted,upadted or deleted, following your model modifications and lifecycle.

Meta data will be treated exactly like attributes, so they can be cast, hidden, and have accessories and mutators available. You don't need to know any new syntax, as it is all manageable with the standard model conventions.

Installation

composer require dottwtson/laravel-model-meta

then publish config files

php artisan vendor:publish --tag=model-meta-config
File config/model-meta-types.php

Here you can set all the available meta types. You can add any kind of meta type for all your needs

<?php
return [
    ...
    // This is the identifier for the meta type
    'int' => [
        // This is the casting that will be applied on the query. %s will be replaced with the meta name
        'database_casting' => 'CAST(%s.value AS UNSIGNED)', 
        // This is the model casting, according with laravale casting
        'model_casting' => 'int'
    ],
    ...
]

Fill free to define all your own meta types

config/model-meta.php

Here you can define all the meta data available on your model.

<?php
return [
        ...
    \My\Namespace\ModelName::class => [
        'mymeta' => ['type'=>\Dottwatson\Meta::JSON,...],
    ],
    ...
    \My\Namespace\ModelName::class => [
        'mymeta' => ['type'=>'json',...], // the type is defined in model-meta-type
        ...
    ]
]

You can also assign a meta list directly on the model (see below).

Implements meta on your existing model

<?php

namespace App\Models;

...
use Dottwatson\ModelMeta\ModelMeta;

class MyModel extends Model
{
    use ModelMeta;
    ...
    protected $tableMeta = 'mymodel_meta';

   ...

}

Define meta directly on the model

<?php

namespace App\Models;

...
use Dottwatson\ModelMeta\ModelMeta;

class MyModel extends Model
{
    use ModelMeta;
    ...
    protected $tableMeta = 'mymodel_meta';

   ...
   
   protected static function metaAttributes()
   {
       return [
        'mymeta' => ['type'=>'json',...], // the type is defined in model-meta-type
       ];
   }
}

For default, the meta data are relationed to the model primary key. For customize it on your needs add this in your model

<?php

namespace App\Models;

...
use Dottwatson\ModelMeta\ModelMeta;

class MyModel extends Model
{
   ...
 
    public static function metaReference()
    {
        return 'my_column';
    }
    
    ...

}

Commands

php artisan make:model-meta MyModel [meta_table_name]

This create a preset model under app\Models, and if passed, creates also the table into database

php artisan make:meta-table meta_table_name

This creates a standalone meta table ready to be used in your model according with the $tableMeta property.

Queries

No modifications are required, No extra methods are implemented. If you use the model builder,each meta will automatically be treated as if it were a column in your table.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固