learn2torials/laravel-modular 问题修复 & 功能扩展

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

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

learn2torials/laravel-modular

Composer 安装命令:

composer create-project learn2torials/laravel-modular

包简介

Laravel Modular App Generator Plugin

README 文档

README

Laravel Release Issues Licence

Turn your existing laravel app into modular application. Laravel modular plugin allows you to write modular plugins for laravel.

Let's say, you are building a blog application. Your blog needs to have following features:

  • comments
  • blog post
  • user management etc..

You can turn this features into a module and bundle your logic so that you can easily use this module for your other projects. You can easily turn on/off your module.

Plugin Requirements

  • PHP >= 7.2
  • Laravel >= 6.0

Newer Laravel Plugin

For older version >= 8.0 of Laravel use this plugin Modular Laravel

How to install this plugin

Run following command to your existing project.


# install this plugin
composer require "learn2torials/laravel-modular"

# create module using artisan
php artisan make:module comments

Above command will create a new directory under App/Modules with following structure.

App
|- Modules
   |-- Comments
      |-- Controllers
      |-- Models
      |-- Views
      |-- Migrations
         |-- Seeder
      |-- Translations
         |-- en
             |-- general.php
         |-- fr
             |-- general.php
      |-- config.php
      |-- routes.php

Next, once this folder structure is generated you can turn on this module by creating console.php file in config directory.

<?php

/*
|--------------------------------------------------------------------------
| Configuration File
|--------------------------------------------------------------------------
|
| You can overwrite default configuration here according to your app requirements.
|
*/
return [
    "prefix"   => null,
    "i18n"     => false,
    "https"    => false,
    "modules"  => [
        "comments" => true
    ]
];

That is it, your module is now enabled. You can verify that your module is working by browsing

http://yourdomain.com/comments

Add prefix before all your modules. Set following config in config/console.php file.

"prefix" => "admin",

Now, your module url will be:

http://yourdomain.com/admin/comments

Enable translation for you module. Set following config in config/console.php file.

"i18n" => true,

Now, your module url will be:

http://yourdomain.com/en/ca/comments      -> for english translation
http://yourdomain.com/fr/ca/comments      -> for french translation

When prefix is enabled

http://yourdomain.com/en/ca/admin/comments -> if prefix is admin
http://yourdomain.com/fr/ca/admin/comments -> if prefix is admin

How to use translations. Check your view file in your module to get the idea of usage:

{{ __('module::file_name.translation_key') }}

Module Configurations

Once module is enabled you can access module related configurations using following syntax.

For example: if you have installed a user module. Configuration file for user module is located in Modules/User/config.php

<?php

/*
|--------------------------------------------------------------------------
| User Module Configurations
|--------------------------------------------------------------------------
|
| Here you can add configurations that relates to your [User] module
| Only make sure not to add any other configs that do not relate to this
| User Module ...
|
*/
return [

    // module name
    'name' => 'User',

    // register middleware
    'middleware' => [
        'user' => \App\Modules\User\Middleware\UserAuthenticated::class,
    ],

    // register service providers
    'providers' => [
        \App\Modules\User\Provider\UserProvider::class
    ],

    // register route middleware
    'route_middleware' => ['user'],

    // database seeder
    'seeder' => [
        __DIR__. '/Migrations/Seeder/UsersTableSeeder.php'
    ]
];

How to run module migration/seeder

To run migration or seeder for your modules. Add seeder to config file and run following commands.


# run module migrations
php artisan migrate

# run module seeders
php artisan db:seed --class="L2T\Database\Seeder"

Reference

Example is shown on https://learn2torials.com/a/laravel-module-management

learn2torials/laravel-modular 适用场景与选型建议

learn2torials/laravel-modular 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 588 次下载、GitHub Stars 达 14, 最近一次更新时间为 2019 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 learn2torials/laravel-modular 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 14
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-06