Comments (20)
No, this is a question related to this package. You probably think I'm talking about hasOne/hasMany relationships in Laravel, but no I'm not.
I'm asking: how do you make entities from one module usable by entities from another module without hard-coding the dependencies? Do I have to create a 3rd module to connect the two modules?
For example, I don't see a user_id field on a Post in the AsgardCMS Blog module. How would you connect the User and the Blog module such that a user_id is available in the Blog module without hardcoding the Post entity into the User module?
from laravel-modules.
I mentioned AsgardCMS to give an example because the maintainer of this package is the creator of the CMS.
This issue does relate to this package . The issue is how can we create relationships between modules without hard-coding the dependencies? If someone can provide a good answer, it would help many people using this package to create even more modular systems.
from laravel-modules.
You would do it the same way, by using the namespace of the second module in your first module.
// in module User
public function posts()
{
return $this->hasMany(Modules\Blog\Models\Posts::class);
}
If you want another way to avoid dependencies that would be up to you to find your preferred approach.
from laravel-modules.
Hi,
This isn't a question related to this package. Please look up the laravel documentation to learn how you can do this. You could also go to the laracasts.com and view the videos.
from laravel-modules.
@armababy Thanks it's the first question popped to my mind when found this library, was suprised its not mentioned anywhere
from laravel-modules.
Here is your solution please check this link
https://github.com/imanghafoori1/eloquent-relativity
from laravel-modules.
You can yes, this is just php indeed.
from laravel-modules.
I don't understand why you mention AsgardCMS here, if it's issue on that you should fill issue there.
You can do relations however you like there are no constraints, this one just separates resources into module like structure, so it's much more easier to maintain without clutter in 1-2 folders.
Example provided by @nWidart is a standart laravel way of doing relation.
from laravel-modules.
Okay, i see what you want.
You can look at this example: AsgardCMS/Page
It's dynamically loaded into entity.
And you can define bunch of them in configs: relation-config
But it's implementation of idea, not really this package specific.
from laravel-modules.
That's great, thanks!
from laravel-modules.
Because it's not this package role to do this. I handled it that way in asgardcms, but you can just as well find a better way to do it altogether. 😄
from laravel-modules.
As another way: https://github.com/greabock/tentacles
Maybe this is not the best way, but there is something to think about.
;)
from laravel-modules.
@n4p4 @nWidart Can't we extend User Model in Post Modules and then add a relationship in the extended User Model?
from laravel-modules.
Using a closure in the config's will break artisan config:cache. Is there a way to __call without passing back a closure from the config?
from laravel-modules.
when i am seeding , newly created modules seeder files are not seed ,
from laravel-modules.
Are you sure, you are using the right command, @kathmandu1
php artisan module:seed Module
?
Otherwise, you can always try with composer dump-autoload, you know just in case.
from laravel-modules.
Hi I stole this answer from Issue 345:
You can define the requirement in the module.json file at the root of the module.
That's how I am probably going to proceed.
from laravel-modules.
I am sorry for bumping this. Yeah, I know .. I can install both packages.
But the “eloquent-relativity” package should be a great addition to this package it self. It is killer feature.
Because it solves a common problem when working with modules, once you want a truly independent modular approach.
from laravel-modules.
I used this approach and it worked.
Check screenshot -
from laravel-modules.
Hi,
This discussion has been going on for quite some time. And it actually helped me a lot about what I want to do in a new project!
But regarding the dependency between modules, I had a question.
How do you deal with dependencies in migrations?
Following the model proposed by the problem.
How do you deal with the user_id that is in the User Module and that will be included in the Post migration that is in the Blog module?
In this case we would still have interdependence between modules, right?
from laravel-modules.
Related Issues (20)
- Extending Laravel 11 EventServiceProvider HOT 1
- Why doesn't SeedCommand have a direction option? HOT 2
- Laravel 11 The route setting in the module is not effective HOT 1
- Target class [cache] does not exist when using Redis as a session driver HOT 3
- include file issue HOT 5
- php artisan module:migrate-refresh Otp not working with me HOT 4
- Class "Modules\Admin\Providers\AdminServiceProvider" not found HOT 12
- Doesn't work correctly asset()
- Enabling Cache on server problem HOT 1
- delete Command Lacks Warning and Confirmation Before Deleting All Modules
- how to extend new layout? HOT 1
- Scan additional folders for modules not working with database seeders
- The package does not emit any events HOT 1
- Migration priority ignored when using artisan migrate HOT 1
- vite-module-loader.js not working on windows os HOT 2
- module based error handling HOT 1
- Class "Modules\Faq\Providers\FaqServiceProvider" not found HOT 3
- Package Installtion Fails Due To "ShowModelCommand" Not Found. Seems to be Looking in Wrong Location. HOT 2
- Trait "Illuminate\Console\Prohibitable" not found HOT 3
- Class CreateTestTable located in ./database/Migrations/2021_05_03_093750_create_test_table.php does not comply with psr-4 autoloading standard Skipping. HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-modules.