定制 oobook/manage-eloquent 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

oobook/manage-eloquent

最新稳定版本:v1.2.3

Composer 安装命令:

composer require oobook/manage-eloquent

包简介

Manage the laravel eloquent model relationships, table columns and column types

README 文档

README

Main Latest Version on Packagist GitHub release (latest SemVer) Total Downloads GitHub Workflow Status

This package will help out you to manage the laravel eloquent model relationships, table columns and column types.

Installation

You can install the package via composer:

composer require oobook/manage-eloquent

Usage

You must define return types of relationships in order to use definedRelationships() method, \Illuminate\Database\Eloquent\Relations\BelongsTo i.e. as following.

<?php

namespace App\Models;

use Oobook\Database\Eloquent\Concerns\ManageEloquent;

class Product extends Model
{
    use ManageEloquent;

    protected $fillable = [
        'name'
    ];


    public function tags(): \Illuminate\Database\Eloquent\Relations\MorphToMany
    {
        return $this->morphToMany(
            Tag::class,
            'taggable'
        );
    }

    public function category(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Category::class);
    }

}

Examples

<?php

$product = new Product();

// RELATIONSHIPS
// get all defined Relationships
$product->definedRelationships(); // ['tags', 'category']
// get relationships by relationship type 
$product->definedRelations('BelongsTo'), // ['category'];
$product->definedRelations(['BelongsTo', 'MorphToMany']), // ['tags', 'category'];

// get relation types
$product->definedRelationsTypes(), 
// [
//     "category" => "BelongsTo"
//     "tags" => "MorphToMany"
// ]

$product->hasRelation('tags') // true;
$product->getRelationType('tags') // \Illuminate\Database\Eloquent\Relations\MorphToMany;

// COLUMNS
$product->hasColumn('name') // true if exists on db table;
$product->getTableColumns() // get the list of columns of the table;

// get the list of timestamp columns of the table;
$product->getTimestampColumns() 

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 oguz.bukcuoglu@gmail.com instead of using the issue tracker.

Credits

License

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

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-20