helloworld
helloworld

Reputation: 485

Laravel 4, cannot update user

In my form i have this {{ Form::open(array('method' => 'put', 'action' => array('UserController@update', $user->id))) }}

And in my controller i have this

public function update($id)
{
    //Find brugeren
    $user = new User($id);
    $user->email    = Input::get("email");
    if ( Input::get("password") != ""){
        $user->password = Hash::make(Input::get("password")); 
    }
    $user->update();

}

Can any help me though this? I am getting this error: Argument 1 passed to Illuminate\Database\Eloquent\Model::__construct() must be of the type array, string given, called in /home/kampmann/public_html/test/laravel-master/app/controllers/UserController.php on line 79 and defined

Upvotes: 1

Views: 1990

Answers (1)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

You should be using the find() method to update your user and save it using save() method:

public function update($id)
{
    //Find brugeren
    $user = User::find($id); /// HERE!
    $user->email = Input::get("email");
    if ( Input::get("password") != ""){
        $user->password = Hash::make(Input::get("password")); 
    }
    $user->save();

}

Upvotes: 5

Related Questions