0

I'm having trouble with a form from laravel to create a user. It keeps on saying "The password field is required". I checked the post and the password is filled. I'm using ardent and have this at the beginning of my user model:

public static $passwordAttributes  = array('password');
public $autoHashPasswordAttributes = true;

and later on:

function setpasswordAttribute($value)
{
    $this->attributes['password'] = Hash::make($value);
}

This is needed to auto hash te password.

Here's the user controller part that handles the post:

public function createUserPost()
{
    var_dump(Input::all());
    $user = new User(Input::except('locations'));
    var_dump($user);

    $user->organisation_id = Auth::user()->organisation_id;

    // get locations
    $input_locations = Input::only('locations');

    if($user->save())
    {
        // Match the id's of location to a new user
        $new_user_id = $user->id;
        foreach ($input_locations as $key => $value) {
            $location = Location::find($value);
            User::find($new_user_id)->locations()->attach($location);
        }
        return Redirect::to('users/'.$user->id);
    }
    return $this->createUser($user)->withErrors($user);
}

At the var_dump($user) I can also see the password.

Really hope someone can help me out because i'm really stuck here. If I need to put more information I'll be glad to give some.

Graham
  • 1,850
  • 4
  • 21
  • 41

1 Answers1

0

This solved it for me. Only thing is the attach method is not working yet.

public function createUserPost()
{
    $user = new User(Input::except('locations','password'));
    $password = Input::only('password');
    $hashed_password = $password['password'];
    $user->password = $hashed_password;

    $user->organisation_id = Auth::user()->organisation_id;

    // pak het field locations
    $input_locations = Input::only('locations');

    if($user->save())
    {
        // Koppel de id's van de locatie aan de nieuwe user
        $new_user_id = $user->id;
        foreach ($input_locations as $key => $value) {
            $location = Location::find($value);
            User::find($new_user_id)->Location()->attach($location);
        }
        return Redirect::to('users/'.$user->id);
    }
    return $this->createUser($user)->withErrors($user);
}
Graham
  • 1,850
  • 4
  • 21
  • 41