Back

Model Update Method


maxguy2099 posted 3 years ago

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

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

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

megadola replied 1 year ago

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

$input = $request->all();
$user = User::findorfail($id);
$updateNow = $user->update($input);
TangeniThePyGuru replied 6 months ago

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!


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us