Laravel-modules: Need help with some architecuting problem for modules by intercommunication between them.

Created on 13 Sep 2018  路  7Comments  路  Source: nWidart/laravel-modules

We are working on a Stock Management app. The core Laravel has the default functionalities. Now we're creating some advance modules for it using this package and it works very well. I need some architecting ideas which can simplify some of our tasks.

  1. Let's say there is an "Add Product" screen. This screen has some limited number of fields.
  2. Now there a module called "Advanced Product". When this module is activated, the "Add Product" screen will have some more input fields related to Advance Products.
  • How can we change the form based on some modules?
  • How will be form data get processed so that some form data get passed to a function from modules?

Basically how to manage intercommunication between modules?

Right now, we have conditional blocks to check if the module is enabled then show the field for it, but feels like there should be some better way to do it.

Looking forward to hearing from you.

Thank you in advance.

Most helpful comment

not sure I follow. Do you want to include a view partial from a module?
You can check if a module is enabled if so, include its view for example.

An implementation example: https://github.com/AsgardCms/Platform/blob/3.0/Themes/Adminlte/views/layouts/master.blade.php#L92

However, this isn't ideal to keep modules decoupled. But as always, there are tradeoffs, sometimes it's worth it.

All 7 comments

Hello!

I suggest using Laravel's event system for module communication.

Regards.

@renanBritz Yes, good point. But for displaying forms fields based on modules, I think to check if a module is enabled or not is the only option. Or do you know some effective way to handle it?

Indeed events are the way to decouple modules for business logic.

In asgardcms I added a helper to check if a module is enabled, could help you maybe: https://github.com/AsgardCms/Platform/blob/3.0/Modules/Core/helpers.php#L26

@nWidart yes this is very helpful, Thanks for sharing.

For views based on modules - do you recommend the having to check in view if modules are enabled or not and based on that show form fields? Or some better way?

not sure I follow. Do you want to include a view partial from a module?
You can check if a module is enabled if so, include its view for example.

An implementation example: https://github.com/AsgardCms/Platform/blob/3.0/Themes/Adminlte/views/layouts/master.blade.php#L92

However, this isn't ideal to keep modules decoupled. But as always, there are tradeoffs, sometimes it's worth it.

This is what I was looking for. Thank you.

I'll close this as there hasn't been a reply in a while, feel free to comment if needed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandeepk2304 picture sandeepk2304  路  3Comments

vdjkelly picture vdjkelly  路  4Comments

alexandretaz picture alexandretaz  路  3Comments

developh picture developh  路  3Comments

firebed picture firebed  路  3Comments