Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

Why dont you just use relationships ?

Last updated 2 years ago.
0

What do you mean?

Last updated 2 years ago.
0

Why not just

class User extends Eloquent{

    public function pages(){ return $this->hasMany('Page'); }

}

Why do you want to make it dynamic ?

Last updated 2 years ago.
0

I want to do it dynamically, becouse I want to build an modular application.

For example I have some modules (Projects, Pages, Photos, Contacts, Calendars etc.) that I may install and uninstall, I don't want to change the User model code for each module with:

public function pages() { return $this->hasMany('Page'); }
public function projects() { return $this->hasMany('Project'); }
public function photos() { return $this->hasMany('Photo'); }
public function contacts() { return $this->hasMany('Contact'); }
public function calendars() { return $this->hasMany('Calendar'); }
// ...

But I want to use:

Auth::user()->pages;
Auth::user()->projects;
// ...

The dynamic way like in my first post seems to be the only way or is there another way to do this?

Last updated 2 years ago.
0

You may rethink how your application is structured. I can't see why there is a problem about specifying every relationships and use them when you need to.

Last updated 2 years ago.
0

I can't specify every relationship in the User model. This is not possible, becouse I can't know what relations would come with the installation of other modules.

I don't know if you are familiar with TYPO3, but this is a good example to explain my problem. TYPO3 has an extension manager to install extensions that are build by 1000s of different developers. Something like that I want to build with Laravel.

So some of these extensions my extend the users-table. You would add the relationships of all the extensions, that could be found on the extension manager in the User-model of the core application? Really? I don't think, that this is a good idea. I think, that if the extensions can extend the User-model like my first post shows would be a better way.

Last updated 2 years ago.
0

You would probably want to use a polymorphic relationship for this. You might be able to accomplish this if you define an extension as a polymorphic relationship, but it still seems pretty complex.

Maybe you should investigate the source code of TYPO3 and see how they manage extensions? They may have come up with a better solution.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

xxpepe84xx xxpepe84xx Joined 24 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.