payter/has-column-many 问题修复 & 功能扩展

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

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

payter/has-column-many

Composer 安装命令:

composer require payter/has-column-many

包简介

This package will provide functionality to add coma separated ID relations for Laravel Eloquent models

README 文档

README

You will be able to make relations of comma separated values in your MySQL table super easely, with adding just few lines of code into your Eloquent model.

It

So if you use Laravel and your relations in the table looks like this, then this package is for you:

Comma separated example PHP Serialized example

Installation

Require package with composer

composer require payter/has-column-many

Basic usage

Using of this package is super easy - you just need to include UseColumnMany trait to your model.

<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use PayteR\UseColumnMany;

class ModelName extends Model
{
    use UseColumnMany;

    public function relateds()
    {
        return $this->hasColumnMany(RelatedModel::class, 'related_ids');
    }
}

And you can call it like any other Eloquent relationships

use App\Models\ModelName;
 
$relateds = ModelName::find(1)->relateds;
 
foreach ($relateds as $related) {
    //
}

Advanced usage

Multiple columns

You are able to concat ID's even from more than one column! It's easy - just pass an array of column names as second parameter:

return $this->hasColumnMany(RelatedModel::class, ['related_ids', 'another_column_ids']);

JSON and Serialised ID's

You don't need to do anything, it will automatically asume if it's comma separated or JSON or Serialized.

You can

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-09