dslk6326846 2016-07-14 07:44
浏览 53
已采纳

在Laravel 5.2外部应用程序上创建模块

I'm currently creating a modular laravel project here was my reference link

Creating a Modular Application in Laravel

Right now I want to create a module folder same directory with my app folder

Folder Structure

I also create a ModuleServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class ModuleServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {

        $modules = config('modules');

        if (ENVIRONMENT != 'local') {

        } else {

            foreach ($modules as $key => $module) {

                // Load the routes for each of the modules
                if(file_exists(__DIR__ . "../../../modules/{$module}/routes.php")) {
                    require __DIR__ . "../../../modules/{$module}/routes.php";
                } else {
                    echo "{$module} Module Not found"; die;
                }

                // Load the views
                if(is_dir(__DIR__ . "../../../modules/{$module}/views")) {
                    $this->loadViewsFrom(__DIR__ . "../../../modules/{$module}/views", $module);
                } else {
                    echo  "{$module} Module View Not found"; die;
                }
            }

        }

    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

I added the ModulerServiceProvider class to my

config/app.php

providers' => [
    App\Providers\ModuleServiceProvider::class,
]

and here is the route under modules/yinyang/route.php being added

Route::group(['prefix' => 'yinyang', 'namespace' => 'Modules\Yinyang\Controllers'], function () {

    Route::get('/', 'GameController@index');
});

Here is the modules/yinyang/controller/GameController.php

namespace Modules\Yinyang\Controllers;

use App\Http\Controllers;

class GameController extends Controller {


    public function __construct() {

    }

    public function index() {

    }

}

And Here is the problem when i am trying to access already the route under yinyang module http://192.168.200.30/try/sample/public/yinyang

Class Modules\Yinyang\Controllers\GameController does not exist

Anyone has any advice/suggestion on how to solve this problem. Thanks.

  • 写回答

1条回答 默认 最新

  • dongqiong8021 2016-07-14 08:20
    关注

    I solve the problem with the help of

    Modular Structure Laravel 5

    For me to access the module directory I need to add new instance on my composer.json Modules to the psr-4

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

    After that run composer dump-autoload to create a new build.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器