Reputation: 63
I tried to make the update document with mongoDB is an update but the problem what I mean is not appropriate. In mongoDB database there are a few users and I want to update user with id: 123 but update not id 123 but first user id 1.
Code:
$user = User:: first ([' _ id ', Input:: get [' id ']]);
$user >-email = ' [email protected] ';
$user >-save ();
How to update that document id = 123?
Upvotes: 0
Views: 7614
Reputation: 550
This worked for me
$user = User::where('_id',Input::get['id'])
->update(['email' => '[email protected]']);
Upvotes: 1
Reputation: 414
Jenssegers\Mongodb\Model
dd($user->toArray());
$user = User::where('_id',Input::get['id']);
if #3 worked something in your configuration( for using Jenssegers's package ) is wrong!
Upvotes: 0
Reputation: 63
After having many failed attempts, I finally found the right one. And here's the answer:
$user = UpdateUser::where('_id' , '=' , Input::get('id'))->first();
$user->username = Input::get('usern');
$user->save()
;
Upvotes: 2
Reputation: 414
$user = User::first(Input::get['id']);
$user->email = '[email protected]';
$user->save();
Upvotes: 1