在我的表格中我有这个
{{ Form::open(array('method' => 'put', 'action' => array('UserController@update', $user->id))) }}
在我的控制器中我有这个
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();
}
虽然这可以帮助我吗?我收到此错误:
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
答案 0 :(得分:5)
您应该使用find()
方法更新用户并使用save()
方法进行保存:
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();
}