承接 nahid-ferdous/laravel-module-generator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nahid-ferdous/laravel-module-generator

最新稳定版本:1.2.70

Composer 安装命令:

composer require nahid-ferdous/laravel-module-generator

包简介

Speeds up Laravel development by automating repetitive tasks. This package helps to generate module files (service, controller, model, migration, resource, request, collection) from YAML file.

README 文档

README

A developer-friendly Laravel package to generate complete modules (Model, Migration, Controller, Service, Resource, Collection, Form Request, and Routes) from a single YAML configuration file. Now includes Authentication & User Management, Postman collection generation, and DB diagram export for streamlined API development and documentation.

✨ Features

  • Generate full Laravel modules from YAML configuration
  • ???? Built-in Authentication & User Management
  • ???? Roles & Permissions Management (Spatie Integration)
  • Customizable stub support (with fallback to internal defaults)
  • Postman collection generation for instant API testing
  • Database diagram export compatible with dbdiagram.io
  • Generates:
    • Models with relationships
    • Database migrations
    • API Controllers
    • Service classes
    • Form Request validation
    • API Resources & Collections
    • Route entries
    • Authentication System
    • User Management System
    • Roles & Permissions System
    • Postman collection files
    • DB diagram files (.dbml)
  • Smart fillable and relationship handling
  • Designed for rapid development and prototyping

???? Installation

Install the package via Composer:

composer require nahid-ferdous/laravel-module-generator --dev

???? Service Provider

Generate required files and configurations:

php artisan module-generator:install

???? Optional: Publish Config & Stubs

You may publish the configuration and stub files to customize them. If you don't publish them, the package will use its built-in defaults automatically.

# Publish configuration file php artisan vendor:publish --tag=module-generator-config # Publish stub files for customization php artisan vendor:publish --tag=module-generator-stubs

This will publish:

  • Config: config/module-generator.php
  • Stubs: module/stub/

???? Authentication & User Management

Generate Authentication System

Generate a complete authentication and user management system with a single command:

php artisan auth:generate

Available Options:

php artisan auth:generate --force # Overwrite existing files without confirmation php artisan auth:generate --skip-roles # Skip roles and permissions setup

What Gets Generated

Authentication Files

  • AuthControllerapp/Http/Controllers/Auth/AuthController.php
  • AuthServiceapp/Services/AuthService.php
  • Login Requestapp/Http/Requests/Auth/LoginRequest.php
  • Register Requestapp/Http/Requests/Auth/RegisterRequest.php
  • Forgot Password Requestapp/Http/Requests/Auth/ForgotPasswordRequest.php
  • Reset Password Requestapp/Http/Requests/Auth/ResetPasswordRequest.php
  • Auth Routesroutes/auth.php

User Management Files

  • UserControllerapp/Http/Controllers/UserController.php
  • UserServiceapp/Services/UserService.php
  • Store User Requestapp/Http/Requests/User/StoreUserRequest.php
  • Update User Requestapp/Http/Requests/User/UpdateUserRequest.php
  • User Resourceapp/Http/Resources/UserResource.php
  • User Collectionapp/Http/Resources/UserCollection.php
  • User Routesroutes/user.php

Roles & Permissions Files (Optional)

  • RoleControllerapp/Http/Controllers/RoleController.php
  • PermissionControllerapp/Http/Controllers/PermissionController.php
  • RoleServiceapp/Services/RoleService.php
  • PermissionServiceapp/Services/PermissionService.php
  • Role Requestsapp/Http/Requests/Role/
  • Permission Requestsapp/Http/Requests/Permission/
  • Role Resourcesapp/Http/Resources/
  • Permission Resourcesapp/Http/Resources/
  • Role Routesroutes/role.php
  • Permission Routesroutes/permission.php
  • Spatie Package → Automatically installed

Authentication Endpoints

The generated authentication system includes:

POST /api/register # Register new user POST /api/login # Login user POST /api/logout # Logout user POST /api/forgot-password # Send password reset link POST /api/reset-password # Reset password GET /api/me # Get authenticated user PUT /api/profile # Update user profile 

User Management Endpoints

GET /api/users # List all users POST /api/users # Create new user GET /api/users/{id} # Get user details PUT /api/users/{id} # Update user DELETE /api/users/{id} # Delete user 

Roles & Permissions Endpoints (Optional)

GET /api/roles # List all roles POST /api/roles # Create role GET /api/roles/{id} # Get role details PUT /api/roles/{id} # Update role DELETE /api/roles/{id} # Delete role POST /api/roles/{id}/permissions # Assign permissions to role GET /api/permissions # List all permissions POST /api/permissions # Create permission GET /api/permissions/{id} # Get permission details PUT /api/permissions/{id} # Update permission DELETE /api/permissions/{id} # Delete permission 

Setup Instructions

After generating the authentication system, follow these steps:

  1. Register Routes in routes/api.php:
// Authentication routes (public) Route::middleware('api')->group(base_path('routes/auth.php')); // User management routes (protected) Route::middleware(['api', 'auth:api'])->group(base_path('routes/user.php')); // Roles & Permissions routes (protected) - if generated Route::middleware(['api', 'auth:api'])->group(base_path('routes/role.php')); Route::middleware(['api', 'auth:api'])->group(base_path('routes/permission.php'));
  1. Install Laravel Sanctum (if not already installed):
composer require laravel/sanctum php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider" php artisan migrate
  1. Update User Model (for roles & permissions):
use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable, HasRoles; // ... rest of your model }
  1. Run Migrations:
php artisan migrate
  1. Configure Mail in .env for password reset:
MAIL_MAILER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=your_username MAIL_PASSWORD=your_password MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=noreply@yourapp.com MAIL_FROM_NAME="${APP_NAME}"

File Replacement Handling

When generating authentication files, if a file already exists:

  • You'll be prompted to confirm replacement
  • Use --force flag to automatically overwrite all files
  • Skip files individually when prompted

????️ Usage

1. Create Your YAML Configuration

Create a YAML file at the default path: module/models.yaml

Define your models with their fields, validation rules, and relationships:

Example: module/models.yaml

User: # all the generatable modules are false,  # so the user model only generates the Postman collection and dbdiagram files generate: model: false migration: false controller: true service: true request: true resource: true collection: true fields: name: string email: string:unique email_verified_at: dateTime:nullable password: string avatar: string:nullable status: boolean:default true last_login_at: timestamp:nullable Unit: fields: name: string:unique code: string:nullable description: string is_active: boolean:default true created_by: foreignId:users:nullable updated_by: foreignId:users:nullable relations: creator: type: belongsTo model: User updater: type: belongsTo model: User UnitConversion: requestParent: Unit fields: from_unit_id: foreignId:units to_unit_id: foreignId:units multiplier: double:default 1 relations: from_unit: type: belongsTo model: Unit to_unit: type: belongsTo model: Unit unique: - [ from_unit_id, to_unit_id ]

2. Generate Your Complete Module

Generate the complete module structure with all features:

php artisan module:generate

Available Options:

php artisan module:generate --force # Overwrite existing files php artisan module:generate --file=custom/path/models.yaml # Use custom YAML file php artisan module:generate --skip-postman # Skip Postman collection generation php artisan module:generate --skip-dbdiagram # Skip DB diagram generation php artisan module:generate --skip-backup # Skip Code Backup generation php artisan module:generate --postman-base-url=https://api.myapp.com # Custom API base URL php artisan module:generate --postman-prefix=api/v2 # Custom API prefix

3. Generate Individual Components

You can also generate specific components separately:

Generate Authentication System

php artisan auth:generate php artisan auth:generate --force php artisan auth:generate --skip-roles

Generate Postman Collection Only

php artisan postman:generate php artisan postman:generate --file=custom/models.yaml php artisan postman:generate --base-url=https://api.myapp.com --prefix=api/v1

Generate DB Diagram Only

php artisan dbdiagram:generate php artisan dbdiagram:generate --file=custom/models.yaml --output=custom/database.dbml

Backup Existing Files While Generating

# Generate with backup (default) php artisan module:generate --file=models.yaml # Generate without backup php artisan module:generate --file=models.yaml --skip-backup # List available backups php artisan module:rollback --list # Rollback to latest backup  php artisan module:rollback # Rollback to specific backup php artisan module:rollback --backup=2025-01-15_14-30-22 # Clean up old backups php artisan module:rollback --cleanup

???? Complete Workflow Example

Here's a complete workflow from YAML to production-ready API with authentication:

# 1. Generate authentication system php artisan auth:generate # 2. Create your YAML schema vim module/models.yaml # 3. Generate everything at once php artisan module:generate --force # 4. Run migrations php artisan migrate # 5. Import Postman collection for testing # File: module/postman_collection.json # 6. Visualize database schema # Copy module/dbdiagram.dbml to dbdiagram.io # 7. Start developing! php artisan serve

???? Roadmap

  • Postman collection generation
  • Database diagram export
  • Authentication & User Management
  • Roles & Permissions (Spatie Integration)
  • Support for additional relationship types
  • GUI for YAML configuration
  • Custom validation rule generation
  • Support for nested resources
  • OpenAPI/Swagger documentation generation
  • Insomnia collection export
  • GraphQL schema generation
  • Two-Factor Authentication (2FA)
  • Social Authentication (OAuth)

???? Recent Updates

v1.1.0

  • NEW: Authentication system generation
  • NEW: User management system
  • NEW: Roles & Permissions with Spatie integration
  • NEW: File replacement confirmation
  • IMPROVED: Better command structure and options

v1.0.10

  • NEW: Postman collection generation
  • NEW: Database diagram export (dbdiagram.io compatible)
  • NEW: Selective component generation
  • IMPROVED: Enhanced command options and flexibility
  • IMPROVED: Better error handling and user feedback

Happy coding! ????

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固