goodcatch/laravel-modules

Laravel Modules 开发

0.1.0 2021-09-22 11:14 UTC

This package is auto-updated.

Last update: 2024-09-29 03:16:24 UTC


README

基于项目 nwidart/laravel-modules

简介

Goodcatch Laravel Modules 库覆盖了 "nwidart/laravel-modules" 服务提供者。

它扩展了 "nwidart/laravel-modules" 库,提供了数据库激活器。

由于 Laravel 包发现,"nwidart/laravel-modules" 已经在 composer.json 中列出。

安装

可能需要做一些稍微复杂的事情。

* add required php composer library
* do minor changes to laravel application
* initialize application
* add first goodcatch laravel-module 'Core'
* getting started development

安装库

composer require goodcatch/laravel-modules

修改应用程序

找到文件 /path_to_project/bootstrap/app.php

将 Kernel 从 app kernel 更改为 goodcatch kernel

例如

// ...

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    Goodcatch\Modules\Laravel\Console\Kernel::class
);


// ...

for mcamara/laravel-localization

make sure Laravel Localization default local is 'en' if no Laravel Localization supported locals
in project configuration file 'project/config/laravellocalization.php' presents.
// ...

return [

    /*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */

    'locale' => 'en',
];

// ...
make sure laravel-localization is configured to laravel http kernel
// ...
class Kernel extends HttpKernel
{

// ...


    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [

        // ...

        // localization

        'localize'                => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,
        'localizationRedirect'    => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
        'localeSessionRedirect'   => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
        'localeCookieRedirect'    => \Mcamara\LaravelLocalization\Middleware\LocaleCookieRedirect::class,
        'localeViewPath'          => \Goodcatch\Modules\Laravel\Http\Middleware\LocalizationViewPath::class

        // ...

    ];

// ...

}

自动加载

默认情况下,模块类不会自动加载。如果模块放在不同的文件夹中,您可以使用 psr-4 自动加载您的模块。例如

{
  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "Goodcatch\\Modules\\": "storage/app/modules"
    }
  }
}

注意:不要忘记确保文件夹 'storage/app/modules' 存在,或者检查环境配置名称 'MODULE_INSTALL_PATH'.

提示:不要忘记之后运行 composer dump-autoload

模块管理页面

Goodcatch Modules 提供了管理页面以显示模块列表以及禁用/启用模块。

首先,生成表并安装它们。

php artisan goodcatch:table

php artisan migrate

php artisan goodcatch:cache

打开模块管理页面: http://domain/goodcatch/laravel-modules/modules

安装第一个模块 Core

composer require goodcatch/laravel-module-core

php artisan module:migrate core --seed

检查模块管理页面,将有一个名为 'Core' 的模块。

开始开发

尚未创建任何模块,首先创建它

创建第一个新模块,名称为 'core'

php artisan module:make core

环境

# optional that pre-append module route path in url
# default to: m
MODULE_ROUTE_PREFIX=m

# optional that change the default modules path from app/Modules to new path
# default to: storage/app/modules
MODULE_INSTALL_PATH=storage/app/modules

# optional that update module
# default to: https://laravel-modules.goodcatch.cn/dl?p=%s&n=%s&v=%s&s=%s
MODULE_INSTALL_REPO_URL=https://laravel-modules.goodcatch.cn/dl?p=%s&n=%s&v=%s&s=%s

# optional that indicate base project that laravel-modules is going to work with
MODULE_INTEGRATE=

许可协议为 The MIT License (MIT)