php - "update" yielding "Creating default object from empty value" Laravel-4 -


route:

route::resource('users','userscontroller') 

userscontroller:

public function edit($id) {     $current = auth::user();     $user = $this->user->find($id);     return view::make('users.edit')->with('current',$current)->with('user',$user); }  public function update($id) {     if( ! $this->user->isvalid(input::all()))     {     return redirect::back()->withinput()->witherrors($this->user->errors);     }      $user = $this->user->find($id);      $user->first_name = input::get('first_name');     $user->email = input::get('email');     $user->password = hash::make(input::get('password')); ...              $user->save();      return redirect::route('users.index'); } 

user model:

protected $table = 'users';   protected $fillable = ['username','email','password'];  public static $rules = [     'first_name' => 'required',     'last_name' => 'required',     'email' => 'required',     'password' => 'required' ]; 

edit.blade.php :

{{ form::model($user, array('method' => 'put', 'route'=>array('users.update','$user'=>'id'))) }} ... {{ form::submit('update user', array('class'=>'button')) }} 

the validation piece seems work fine; if leave out required field, redirects error messages , input. if required fields filled, yields error: "creating default object empty value" , quotes starting code update function on userscontroller. same code works fine create function. don't see i'm making error. thanks!

you not passing user id correctly in form method.

change

{{ form::model($user, array('method' => 'put', 'route'=>array('users.update','$user'=>'id'))) }} 

to

{{ form::model($user, array('method' => 'put', 'route'=>array('users.update',$user->id))) }} 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -