Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to validate addtional fields and save part details to another table #490

Closed
donenvy opened this issue Jan 6, 2015 · 7 comments
Closed
Labels

Comments

@donenvy
Copy link

donenvy commented Jan 6, 2015

Hi all,

I'm hoping someone can help as I have been pulling my hair out on this. Whilst this plugin works great out of the box. It seems making any customizations is a chore and half.

All I wanted to do was add some additonal fields, validate them and save one part to the users table and the other address fields to a different table.

I can't find any instruction on how to do this? Can anyone advise with an example?

@donenvy
Copy link
Author

donenvy commented Jan 6, 2015

I've tried adding a customer validator, which when adding all the fileds to the $user object it all works ok. But as soon as I try and seperate it so one part goes to one table and one to the other, I get password_mismtach error

@rjp2525
Copy link

rjp2525 commented Jan 6, 2015

I'm having a similar issue, but not quite the same.. My issue is that if I attempt to add any sort of custom fields with custom validation and addition MySQL columns, I can't confirm the user no matter what. Not sure what's going on here, but Confide is not easily customizable I agree.

Edit: For your issue, have you tried creating a separate model and using a new instance in the signup() method? (in UserRepository.php)

@donenvy
Copy link
Author

donenvy commented Jan 6, 2015

I haven't created a new model but I have edited the existing one in signup(). The strange thing is when I am validating using the default $user = new User everything works. But soon as I change that it stops working. e.g I tried creating a new instance of user $user2 = new User and tried to see if I can insert anything into users table manually without validation and it will not work. It's the default $user = new User is stopping me from entering in anything manually

@donenvy
Copy link
Author

donenvy commented Jan 6, 2015

for example I added this to the model to see if it goes in manually

    $user2 = new User;
    $user2->username = 'name';
    $user2->email    = 'email';
    $user2->password = 'test';
    $user2->first_name = 'firstname';
    $user2->save();

    return $user2;

I still get "The passwords did not match." error. Here I have not asked to validate anything, I'm putting it straight in. I thought the save function at the bottom of UserRepository might interfering with the normal save function, but even removing that made no difference, it is still trying to force validation.

I am guessing it is to do with the following piece of code in
vendor\zizaco\confide\src\Confide\ConfideUser.php

/**
 * Overwrites the original save method in order to perform
 * validation before actually saving the object.
 *
 * @param array $options
 *
 * @return bool
 */


public function save(array $options = array())
{
    if ($this->isValid()) {
        return parent::save($options);
    }

    return false;
}

why is the validation not being done separately and the save being done separately? This it automatically trying to save and validate it at the same time, whilst overwriting the original save, meaning you can't hook into it and can't use a separate instance to save because it is being overwritten?

@donenvy
Copy link
Author

donenvy commented Jan 6, 2015

Looks like someone else with a similar issue with save function, messing up doing anything else. Would be nice to clarify how this should be done without modifying vendor package

http://stackoverflow.com/questions/27805753/laravel-confide-unable-to-confirm-user-with-custom-validation

@donenvy
Copy link
Author

donenvy commented Jan 7, 2015

I give up, this package is proving to be a pain in the butt to customize. Wish it was more user friendly, all these loops and holes you have to jump through just to add some columns into a different table at the time of validation, you can't intercept the override save function, to determine what should be saved and what needs to transfer across without modifying the vendor files, plus where is the documentation looks like not much exists for anything.

@Zizaco
Copy link
Owner

Zizaco commented Jan 31, 2015

@donenvy I really didn't get what you were not able to do.

You want the User to HasMany Addresses? Why you coudn't make it? Can you show me your validator and your user model? (Then we may re-open this issue)

@Zizaco Zizaco closed this as completed Jan 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants