nWidart / laravel-modules

Module Management In Laravel
https://docs.laravelmodules.com
MIT License
5.52k stars 959 forks source link

Creating a subfolder module #1248

Closed devhus closed 3 years ago

devhus commented 3 years ago

Hello, I don't know if this is a bug or that's how it should be. I want to have my modules to be created in subfolders with the folder names in the module's classes namespace. But when trying to create a module within a subfolder php artisan module:make Store\Product it will throw this error:

Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/module.json
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/Routes/web.php
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/Routes/api.php
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/Resources/views/index.blade.php
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/Resources/views/layouts/master.blade.php
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/Config/config.php
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/composer.json
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/Resources/assets/js/app.js    
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/Resources/assets/sass/app.scss
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/webpack.mix.js
Created : C:\xampp\htdocs\bnaturalia\bnaturalia-api\Modules/Store\Product/package.json

   Nwidart\Modules\Exceptions\ModuleNotFoundException 

  Module [Store\Product] does not exist!

  at C:\xampp\htdocs\bnaturalia\bnaturalia-api\vendor\nwidart\laravel-modules\src\FileRepository.php:396
    392▕         if ($module !== null) {
    393▕             return $module;
    394▕         }
    395▕
  ➜ 396▕         throw new ModuleNotFoundException("Module [{$name}] does not exist!");
    397▕     }
    398▕
    399▕     /**
    400▕      * Get all modules as laravel collection instance.

  1   C:\xampp\htdocs\bnaturalia\bnaturalia-api\vendor\nwidart\laravel-modules\src\Traits\ModuleCommandTrait.php:16
      Nwidart\Modules\FileRepository::findOrFail("Store\Product")

  2   C:\xampp\htdocs\bnaturalia\bnaturalia-api\vendor\nwidart\laravel-modules\src\Commands\SeedMakeCommand.php:85
      Nwidart\Modules\Commands\SeedMakeCommand::getModuleName()
SocolaDaiCa commented 3 years ago

this package not work with php artisan module:make Store\Product Please use php artisan module:make Product if You want create package Product inside folder Store, please config

 'paths' => [
        /*
        |--------------------------------------------------------------------------
        | Modules path
        |--------------------------------------------------------------------------
        |
        | This path used for save the generated module. This path also will be added
        | automatically to list of scanned folders.
        |
        */

        'modules' => base_path('Modules'), // change to base_path('Modules/Store')
SocolaDaiCa commented 3 years ago

or change scan config

    'scan' => [
        'enabled' => false,
        'paths' => [
            base_path('vendor/*/*'),
        ],
    ],

or register autoload to Modules/Store

devhus commented 3 years ago

this package not work with php artisan module:make Store\Product Please use php artisan module:make Product if You want create package Product inside folder Store, please config

 'paths' => [
        /*
        |--------------------------------------------------------------------------
        | Modules path
        |--------------------------------------------------------------------------
        |
        | This path used for save the generated module. This path also will be added
        | automatically to list of scanned folders.
        |
        */

        'modules' => base_path('Modules'), // change to base_path('Modules/Store')

i don't want to change the Modules path, I just want to add some modules in system-based folders and namespace

devhus commented 3 years ago

or change scan config

    'scan' => [
        'enabled' => false,
        'paths' => [
            base_path('vendor/*/*'),
        ],
    ],

or register autoload to Modules/Store

will that allow me to add \Store in the namespace or it will just look for Modules\Product instead of having \Modules\Store\Product ?

SocolaDaiCa commented 3 years ago

or change scan config

    'scan' => [
        'enabled' => false,
        'paths' => [
            base_path('vendor/*/*'),
        ],
    ],

or register autoload to Modules/Store

will that allow me to add \Store in the namespace or it will just look for Modules\Product instead of having \Modules\Store\Product ?

You can try,

    'scan' => [
        'enabled' => true,
        'paths' => [
            base_path('Modules/*/*'),
        ],
    ],

It will scan package insilde Modules/Store/Product

Default laravel-packages only scan package inside Modules folder

devhus commented 3 years ago

You can try,

    'scan' => [
        'enabled' => true,
        'paths' => [
            base_path('Modules/*/*'),
        ],
    ],

It will scan package insilde Modules/Store/Product

Default laravel-packages only scan package inside Modules folder

I have tried adding it to the scan config, but still not able to use php artisan module:make Store/Product I only can create php artisan module:make Product and move it into the Store folder but this not just enough since the Product module's classes namespace will remain as Modules\Product\Http\Controllers\ProductController instead of having Modules\Store\Product\Http\Controllers\ProductController which is what is needed to be. Renaming the namespace in the module's files manually should not be an option at a 2021 package.

Adding a module in the folder without having the folder name in the classes namespace is not a good code structure

SocolaDaiCa commented 3 years ago

why you not rename Modules to Store and put Prodcut inside Store

devhus commented 3 years ago

why you not rename Modules to Store and put Prodcut inside Store

Renaming the namespace in the module's files manually should not be an option at a 2021 package.

SocolaDaiCa commented 3 years ago

No no, rename folder Modules to Store and config namespace and Modules path

<?php

use Nwidart\Modules\Activators\FileActivator;
use Nwidart\Modules\Commands;

return [

    /*
    |--------------------------------------------------------------------------
    | Module Namespace
    |--------------------------------------------------------------------------
    |
    | Default module namespace.
    |
    */

    'namespace' => 'Store',
    'paths' => [
        /*
        |--------------------------------------------------------------------------
        | Modules path
        |--------------------------------------------------------------------------
        |
        | This path used for save the generated module. This path also will be added
        | automatically to list of scanned folders.
        |
        */

        'modules' => base_path('Store'),

when you run php artisan module:make Product, It will create Package Product with namespace is Store/Product inside folder Store

devhus commented 3 years ago

No no, rename folder Modules to Store and config namespace and Modules path

<?php

use Nwidart\Modules\Activators\FileActivator;
use Nwidart\Modules\Commands;

return [

    /*
    |--------------------------------------------------------------------------
    | Module Namespace
    |--------------------------------------------------------------------------
    |
    | Default module namespace.
    |
    */

    'namespace' => 'Store',
    'paths' => [
        /*
        |--------------------------------------------------------------------------
        | Modules path
        |--------------------------------------------------------------------------
        |
        | This path used for save the generated module. This path also will be added
        | automatically to list of scanned folders.
        |
        */

        'modules' => base_path('Store'),

when you run php artisan module:make Product, It will create Package Product with namespace is Store/Product inside folder Store

as i said i don't want to change the modules base path, since there will be other system-based folders this is not a good idea

--- Modules
----- User
----- Account
----- Comment
----- Store
------- Category
------- Product
------- Option
----- Courses
------- Course
------- Registration

your solution doesn't work with the example of the paths above since your solution is just replacing Modules with Store but nothing has really changed

wikigods commented 3 years ago

First of all this method does not exist php artisan module:make Store\Product

One solution is to create a command and do the necessary logic required to implement it.

The second solution is to create all files manually and register them in the service provider of the created module.

the third one is to pass it subfolder I don't know if it is what you need example:

php artisan module:make-controller Product/ProductController Store will result in the main module Store subfolder Product inside will be your controller, php artisan module:make-model Product/Product Store

will have result Main module Store subfolder Product inside will be your Model, check the documentation of the web or pass helper help in your terminal to see the commands and how they work. What you want to do can not be done you must do well first step or second step reviewing its structure as you want to have it would be something like this. https://nwidart.com/laravel-modules/v6/advanced-tools/artisan-commands --- Modules ----- User ----- Account ----- Comment ----- Store Main Module ------- Category don't create subfolder the correct thing would be model and controller I will attach image ------- Product ------- Option ----- Courses ------- Course ------- Registration

Screenshot_153

devhus commented 3 years ago

First of all this method does not exist php artisan module:make Store\Product

One solution is to create a command and do the necessary logic required to implement it.

The second solution is to create all files manually and register them in the service provider of the created module.

the third one is to pass it subfolder I don't know if it is what you need example:

php artisan module:make-controller Product/ProductController Store will result in the main module Store subfolder Product inside will be your controller, php artisan module:make-model Product/Product Store

will have result Main module Store subfolder Product inside will be your Model, check the documentation of the web or pass helper help in your terminal to see the commands and how they work. What you want to do can not be done you must do well first step or second step reviewing its structure as you want to have it would be something like this. https://nwidart.com/laravel-modules/v6/advanced-tools/artisan-commands --- Modules ----- User ----- Account ----- Comment ----- Store Main Module ------- Category don't create subfolder the correct thing would be model and controller I will attach image ------- Product ------- Option ----- Courses ------- Course ------- Registration

Screenshot_153

I think the method should be created and give the ability to create submodules inside a module, it will be much better than having a whole project(e-commerce) logic inside one module. It can't be called a modular app if each module includes 50% of the website logic. So if it is not a bug could be a feature request?

wikigods commented 3 years ago

I would recommend you to make Pull requests, and that you add that functionality to the package, but as I said before you must make a function to create sub folders and the necessary command for terminal.

I recommend you to see asgard https://github.com/AsgardCms/Platform

devhus commented 3 years ago

I would recommend you to make Pull requests, and that you add that functionality to the package, but as I said before you must make a function to create sub folders and the necessary command for terminal.

I recommend you to see asgard https://github.com/AsgardCms/Platform

might do it after i finish up my current project, thx for the tips

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.