定制 soysaltan/marygen 二次开发

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

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

soysaltan/marygen

Composer 安装命令:

composer require soysaltan/marygen

包简介

Generate MaryUI based pages with one line command

README 文档

README

Table of Contents

  1. Introduction
  2. Features
  3. Requirements
  4. Installation
  5. Configuration
  6. Usage
  7. Command Structure
  8. Generated Components
  9. Customization
  10. Translation Feature
  11. Troubleshooting
  12. Contributing
  13. License
  14. Support

Introduction

MaryGen is a powerful Laravel package designed to streamline the process of generating MaryUI components and Livewire pages for your Laravel models. It automates the creation of CRUD (Create, Read, Update, Delete) interfaces, saving developers significant time and effort in setting up admin panels or data management systems.

Features

  • Automatic generation of MaryUI components for Laravel models
  • Creation of Livewire pages with full CRUD functionality
  • Intelligent form field generation based on database schema
  • Automatic table column generation
  • Built-in sorting, pagination, and search capabilities
  • Easy customization options
  • Automatic route generation
  • Translation support for generated content (new in version 0.35.0)

Requirements

Installation

  1. Ensure you have a Laravel project set up.

  2. Install the MaryUI:

    https://mary-ui.com/docs/installation

  3. Install the Livewire, Livewire Volt packages (if not already installed with MaryUI):

    composer require livewire/livewire livewire/volt && php artisan volt:install
  4. Install the MaryGen package:

    composer require soysaltan/marygen
  5. (Optional) Publish the configuration file:

    php artisan vendor:publish --provider="SoysalTan\MaryGen\MaryGenServiceProvider" --tag="config"

Configuration

After publishing the configuration file, you can modify config/marygen.php to customize the package behavior:

return [
    'model_namespace' => 'App\Models',
    'use_mg_like_eloquent_directive' => true,
];
  • model_namespace: Define the namespace for your models. Default is App\Models.
  • use_mg_like_eloquent_directive: Determine whether to use the MgLike Eloquent directive for search functionality. For example:
$q->mgLike(['id', 'username', 'email', 'password', 'name', 'lastname', 'title', 'phone', 'avatar', 'time_zone', 'last_login_at', 'status', 'created_at', 'updated_at'], $this->search))

Usage

To generate a MaryUI component and Livewire page for a model, use the following command:

php artisan marygen:make {--m|model=} {--w|view=} {--d|dest_lang=} {--s|source_lang=} {--nr|no-route}
  • --m|model: The name of the model for which you want to generate the components.
  • --w|view: (Optional) The name of the view file. If not provided, it will use the lowercase model name.
  • --d|dest_lang: (Required if source_lang presents) The destination language code for translation.
  • --s|source_lang: (Optional) The source language code for translation.If not present, it detects the source language automatically.
  • --nr|no-route: (Optional - as of v0.35.2) Prevent automatic route addition to routes/web.php.

Example:

php artisan marygen:make --model=User --view=admin-users --dest_lang=es --no-route

This command will generate a Livewire page for the User model with CRUD functionality, name the view file admin-users.blade.php, and translate the content from English to Spanish and skip the automatic route generation.

Prevent Automatic Route Generation (as of v0.35.2)

Starting from version 0.35.2, MaryGen prevents automatic route generation feature. By default, when you generate a new component without using --no-route option with the marygen:make command, a corresponding route is automatically added to your routes/web.php file.

New in Version 0.36.1: Multi-Database Connection Support

As of version 0.36.1, MaryGen now supports models that use different database connections. This feature allows you to generate components and pages for models that are associated with databases other than your default connection.

How it works

MaryGen now respects the $connection property of your Eloquent models. When generating components and pages, it will use the specified connection to:

  1. Retrieve the correct table schema
  2. Generate appropriate form fields
  3. Create table columns
  4. Set up sorting and filtering

Usage

No additional configuration is required. Simply ensure that your model specifies the correct connection:

class User extends Model
{
    protected $connection = 'secondary_db';

    // ... rest of your model
}

When you run the marygen:make command for this model, MaryGen will automatically use the 'secondary_db' connection for all database operations.

Example

php artisan marygen:make --model=User

If the User model specifies a different connection, MaryGen will use that connection to generate the component and page.

Notes

  • Ensure that all specified connections are properly configured in your config/database.php file.
  • If a model doesn't specify a connection, MaryGen will use the default database connection.
  • This feature is particularly useful for applications that interact with multiple databases or use database sharding.

Customization

You can customize the generated components by modifying the following methods in the MaryGenCommand class:

  • getMaryUIComponent(): Adjust the mapping between database column types and MaryUI components.
  • getIconForColumn(): Modify the icon selection for form fields.
  • generateLivewirePage(): Customize the structure of the generated Livewire component and Blade view.

Additionally, you can edit the generated files directly to further tailor them to your specific needs.

Translation Feature

MaryGen includes a translation feature that allows you to generate content in different languages. This feature uses the Google Translate API to translate field names, labels, and other text elements in the generated components. It uses stichoza/google-translate-php package. (https://github.com/Stichoza/google-translate-php) To use the translation feature:

  1. Specify the destination language using the --dest_lang option when running the marygen:make command.
  2. Optionally, specify the source language using the --source_lang option. If not provided, Google Translate will attempt to auto-detect the source language.

Example:

php artisan marygen:make --model=Product --view=product-management --dest_lang=fr --source_lang=en

This command will generate the components for the Product model and translate the content from English to French.

Note: The translation feature requires an active internet connection to communicate with the Google Translate API.

Troubleshooting

Common issues and their solutions:

  1. MaryUI package not found:

    • Error: MaryUI package not found! Please install using: 'composer req robsontenorio/mary'
    • Solution: Run composer require robsontenorio/mary to install the MaryUI package.
  2. Livewire Volt package not found:

    • Error: Livewire Volt package not found! Please see doc: 'https://livewire.laravel.com/docs/volt#installation'
    • Solution: Install Livewire Volt using composer require livewire/livewire livewire/volt && php artisan volt:install.
  3. Model not found:

    • Error: Model {modelName} does not exist!
    • Solution: Ensure the specified model exists in your model namespace (default: App\Models).
  4. View file already exists:

    • Error: File {viewName}.blade.php already exists!
    • Solution: Choose a different name for your view or manually delete the existing file if you want to overwrite it.
  5. Translation errors:

    • Error: Various Google Translate API errors
    • Solution: Ensure you have an active internet connection and that the language codes you're using are valid. Check the Google Translate documentation for supported language codes.
  6. Route generation issues:

    • Problem: Unwanted routes being added to routes/web.php
    • Solution: Use the --no-route option when running the marygen:make command to prevent automatic route generation.

Contributing

Contributions to MaryGen are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Write your code and tests
  4. Submit a pull request with a clear description of your changes

Please ensure your code adheres to the existing style conventions and includes appropriate tests.

License

MaryGen is open-source software licensed under the MIT license.

Support

For more information or support:

  • Open an issue on the GitHub repository
  • Contact the package maintainer through the repository's contact information

For the latest updates and more detailed information about MaryUI, please visit the official MaryUI documentation.

soysaltan/marygen 适用场景与选型建议

soysaltan/marygen 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 137 次下载、GitHub Stars 达 27, 最近一次更新时间为 2024 年 09 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ui」 「components」 「laravel」 「blade」 「tailwind」 「livewire」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 soysaltan/marygen 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 soysaltan/marygen 我们能提供哪些服务?
定制开发 / 二次开发

基于 soysaltan/marygen 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 27
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

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