定制 teksite/module 二次开发

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

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

teksite/module

最新稳定版本:3.0.0

Composer 安装命令:

composer require teksite/module

包简介

a package to create modules for a laravel project

README 文档

README

A comprehensive Laravel package that brings modularity to your applications. It allows you to organize your code into reusable, self-contained modules — each with its own controllers, models, views, and service providers. The package provides Artisan commands similar to Laravel's native ones, prefixed with module: for easy module management.

Table of Contents

About

The Modular Laravel Package (teksite/module) enables full modularity in Laravel applications. Modules are stored in the Lareon/Modules directory, each replicating a mini Laravel structure. The package mirrors native Laravel Artisan commands but prefixes them with module: to avoid conflicts.

Note: From version 3 onward, this package is merged with teksite/lareon. Both functionalities are now provided in a single package.

Author

Sina Zangiband

Contact

Contact

Installation

Compatibility

Laravel Version Package Version
11.x ^1.0
12.x ^2.0
13.x ^3.0

Step 1: Install via Composer

Run the following command:

  composer require teksite/module

Note on wikimedia/composer-merge-plugin

If prompted with:

Do you trust "wikimedia/composer-merge-plugin" to execute code and wish to enable it now?

Press y and Enter. This plugin is required to merge composer.json files from modules.

Note on wikimedia/composer-merge-plugin

If prompted with: Do you trust "wikimedia/composer-merge-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] Press y and Enter. This plugin is required to merge composer.json files from modules.

Step 2: Register the Service Provider

Note: For Laravel 5.5 and above, auto-discovery handles this automatically. The following step is optional for newer versions.

Laravel 10 and above

Add the provider to bootstrap/providers.php:

<?php

return [
    // ...
    Teksite\Module\ModuleServiceProvider::class,
];

Laravel 5.x and Earlier

Add the provider to config/app.php under providers:

'providers' => [
    // ...
    Teksite\Module\ModuleServiceProvider::class,
],

Step 3: Publish Configuration (Optional)

Publish the configuration files for customization:

  php artisan vendor:publish --provider="Teksite\Module\ModuleServiceProvider"

The package publishes two config files:

  • modules.php – general package behavior
  • modules-hq.php – control over modules managed by Steward (e.g., routing)

Both are accessible via config('modules').

Step 4: Update composer.json

To enable autoloading of modules and the Steward provider, add the following to your composer.json:

"extra": {
    "laravel": {
        "dont-discover": []
    },
    "merge-plugin": {
        "include": [
            "lareon/steward/composer.json",
            "lareon/modules/*/composer.json"
        ]
    }
}

Step 5: Clear Cache

Run the following commands to clear cached data:

  php artisan cache:clear
  php artisan config:clear

Step 6: Refresh Autoloader

Run Composer's autoload dump:

  composer dump-autoload

Step 7: Install Steward (Optional but Recommended)

To install Steward, run:

php artisan module:steward

If Steward is not installed, each module must be managed independently.

Usage

Creating a Module

Generate a new module with a structure similar to Laravel:

  php artisan module:make Example

Or create a module managed by Steward:

  php artisan module:make Example --steward
  • By default, modules are created in lareon/Modules/{Example}.
  • The --steward flag indicates that the module should be managed by Steward (registration of views, configs, routes, etc. are in control of Steward).

Module Commands

All module‑specific Artisan commands are prefixed with module:.

Examples

  • Create a controller:
  php artisan module:make-controller ExampleController ExampleModule --resource
  • Create a model:
  php artisan module:make-model ExampleModel -a ExampleModule
  • Create a middleware:
  php artisan module:make-middleware ExampleMiddleware ExampleModule
  • And other laravel command.

Note: Replace ExampleModule with your actual module name. To create files inside Steward (instead of a module), use Steward as the module name.

Changing Module Priority

To adjust the loading order of modules, edit the bootstrap/modules.php file. Reorder the array to prioritize specific modules:

<?php

return [
    'Blog' => [
        'provider' => 'Lareon\\Modules\\Blog\\App\\Providers\\BlogServiceProvider',
        'active'   => true,
        'type'     => 'lareon',
    ],
    'Page' => [
        'provider' => 'Lareon\\Modules\\Page\\App\\Providers\\PageServiceProvider',
        'active'   => true,
        'type'     => 'self',
    ],
];

Change Mode

To switch an existing module between steward‑controlled (steward) and self‑managed (self), update the type in bootstrap/modules.php:

'Example' => [
    'provider' => 'Lareon\\Modules\\Example\\App\\Providers\\ExampleServiceProvider',
    'active'   => true,
    'type'     => 'steward', // change to 'self' for self‑managed or steward to managed by Steward
],

and update the $type property in {ModuleName}ServiceProvider:

/**
 * Module type (self|steward)
 *
 * @var string
 */
protected string $type = "steward"; // change to 'self' for self‑managed or steward to managed by Steward

Integration with Lareon

This package is now merged with teksite/lareon. The main difference in naming is steward instead of previous terms like cms.

To switch an existing module between steward-controlled (steward) and self-managed (self), update the type in bootstrap/modules.php:

'Example' => [
    'provider' => 'Lareon\\Modules\\Example\\App\\Providers\\ExampleServiceProvider',
    'active' => true,
    'type' => 'steward', // or 'self'
],

and update {ModuleName}ServiceProvider

    /**
     * Module type (self|steward)
     *
     * @var string
     */
    protected string $type = "steward"; //self to managed by the module itself or steward to manage by Steward

Warning: Changing between these two modes generally does not cause issues, provided you do not override internal methods.

Credits

License

This package is open‑sourced under the MIT License.

Support

For questions, issues, or feature requests, please reach out via:

Contributions are welcome! Feel free to submit a pull request or open an issue on GitHub.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固