Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Syncing attributes to another table #123

Closed
ghost opened this issue Jun 19, 2016 · 2 comments
Closed

Syncing attributes to another table #123

ghost opened this issue Jun 19, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Jun 19, 2016

Good Day,

I just wanted to know if it is possible to sync user details to another table other than users. For example, if one is implementing polymorphic relations and uses the users table and thus the User model, to only store details necessary for authentication e.g email, username etc. How would one then sync e.g the name,office number etc., to a child model?

Kind Regards.

@stevebauman
Copy link
Member

Hi @Mylo-92, good question!

So for example, if you had a user_details one to one relationship, the easiest way would be to use the bind_user_to_model option and set it to true. Then after authentication, you could grab the details and save them to the relationship model.

For example:

// Auth/AuthController.php
public function authenticated(Request $request, User $user)
{
    $user->details()->firstOrCreate([
        'office_number' => $user->adldapUser->getTelephoneNumber();
    ]);
}

Another option, is to override one of the trait methods such as syncModelFromAdldap(), since you'll have both the laravel model and the LDAP user model in the same method to perform synchronization.

https://github.com/Adldap2/Adldap2-Laravel/blob/master/src/Traits/ImportsUsers.php#L86

Though this should be easier, so I'll add an easily override-able method to allow this and will comment back when it's been implemented.

@ghost
Copy link
Author

ghost commented Jun 21, 2016

Thank you! Can't wait 💯 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant