Forum

Model Update Method

I want to know if I can use this:

User::update($id,array(
                    'username '=>Input::get('username'),
                    'email '=>Input::get('email ')
                ));

Insted of this:

$user = User::find($id);
$user->username =Input::get('username');
$user->email = Input::get('email ');
$user->save();

I tried but I'm getting the next error: Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically, assuming $this from incompatible context

maxguy2099
maxguy2099
  • 3 years ago
0xMatt
Solution
User::where('id', $id)->update(array('username' => Input::get('username'), 'email' => Input::get('email')));

showing error like this The HTTP status code "5" is not valid.

Quick one to do, if you are using CRUD with resource controllers

$input = $request->all();
$user = User::findorfail($id);
$updateNow = $user->update($input);

megadola said:

Quick one to do, if you are using CRUD with resource controllers

$input = $request->all();
$user = User::findorfail($id);
$updateNow = $user->update($input);

thanks. it worked!