noouh/auto-model 问题修复 & 功能扩展

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

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

noouh/auto-model

最新稳定版本:v1.0.2

Composer 安装命令:

composer require noouh/auto-model

包简介

A Laravel package to auto-generate models and migrations from table definitions.

README 文档

README

A Laravel package to auto-generate models and migrations from table definitions.

About the Company

Noouh For Integrated Solutions is dedicated to providing innovative software solutions. We specialize in developing high-quality applications tailored to meet the specific needs of our clients.

Installation

To install the Noouh Auto Model package, you can require it using Composer:

composer require noouh/auto-model

Publish the Stubs

After installing the package, publish the stubs using the following command:

php artisan vendor:publish --tag=stubs

This will publish the model.stub and migration.stub files to your project's stubs directory.

Usage

Create a JSON file (e.g., tables.json) with your table definitions and relationships. Here is an example structure:

[
  {
    "table": "users",
    "columns": [
      { "name": "name", "type": "string" },
      { "name": "email", "type": "string" }
    ]
  },
  {
    "table": "posts",
    "columns": [
      { "name": "title", "type": "string" },
      { "name": "content", "type": "text" },
      { "name": "user_id", "type": "unsignedBigInteger" }
    ],
    "relationships": [
      { "type": "belongsTo", "relatedTable": "users", "foreignKey": "user_id" }
    ]
  }
]

Run the command to generate models and migrations:

php artisan generate:models /path/to/tables.json

Example

Given the following tables.json file:

[
  {
    "table": "users",
    "columns": [
      { "name": "name", "type": "string" },
      { "name": "email", "type": "string" }
    ]
  },
  {
    "table": "posts",
    "columns": [
      { "name": "title", "type": "string" },
      { "name": "content", "type": "text" },
      { "name": "user_id", "type": "unsignedBigInteger" }
    ],
    "relationships": [
      { "type": "belongsTo", "relatedTable": "users", "foreignKey": "user_id" }
    ]
  }
]

Running the command:

php artisan generate:models /path/to/tables.json

Will generate:

  • A User model in app/Models/User.php
  • A Post model in app/Models/Post.php with a belongsTo relationship to the User model
  • A migration file for the users table
  • A migration file for the posts table with a foreign key to the users table

License

This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

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