Coder Social home page Coder Social logo

Comments (20)

n4p4 avatar n4p4 commented on May 21, 2024 15

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.

n4p4 avatar n4p4 commented on May 21, 2024 14

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.

nWidart avatar nWidart commented on May 21, 2024 13

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.

nWidart avatar nWidart commented on May 21, 2024 10

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.

boynet avatar boynet commented on May 21, 2024 3

@armababy Thanks it's the first question popped to my mind when found this library, was suprised its not mentioned anywhere

from laravel-modules.

bilalsheikh1 avatar bilalsheikh1 commented on May 21, 2024 3

Here is your solution please check this link
https://github.com/imanghafoori1/eloquent-relativity

from laravel-modules.

nWidart avatar nWidart commented on May 21, 2024 2

You can yes, this is just php indeed.

from laravel-modules.

armababy avatar armababy commented on May 21, 2024 1

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.

armababy avatar armababy commented on May 21, 2024

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.

n4p4 avatar n4p4 commented on May 21, 2024

That's great, thanks!

from laravel-modules.

nWidart avatar nWidart commented on May 21, 2024

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.

 avatar commented on May 21, 2024

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.

twf-nikhila avatar twf-nikhila commented on May 21, 2024

@n4p4 @nWidart Can't we extend User Model in Post Modules and then add a relationship in the extended User Model?

from laravel-modules.

turbo124 avatar turbo124 commented on May 21, 2024

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.

kathmandu1 avatar kathmandu1 commented on May 21, 2024

when i am seeding , newly created modules seeder files are not seed ,

from laravel-modules.

beganovich avatar beganovich commented on May 21, 2024

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.

brideo avatar brideo commented on May 21, 2024

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.

robsontenorio avatar robsontenorio commented on May 21, 2024

@bilalsheikh1 @nWidart

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.

twf-nikhila avatar twf-nikhila commented on May 21, 2024

I used this approach and it worked.

Check screenshot -

image

from laravel-modules.

iacreative avatar iacreative commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.