Reputation: 2329
Laravel 5.5 show me the error message:
Call to undefined method stdClass::update()
for the following codes in the Model
DB::table('adminUserLogs')
->where('adminUserId', $id)
->where('adminUserOutTime', NULL)->first()
->update(['adminUserOutTime' => \Carbon\Carbon::now()]);
Upvotes: 1
Views: 6829
Reputation: 7615
In Laravel if you wish to update only one record then you can use ->first()
method of Eloquent ORM to get eloquent object and then you can simply update the object by ->save()
.
Laravel query builder directly not supporting update only record as Update with limit of 1 is not directly supported by mysql MySQL - UPDATE query with LIMIT
In the example you have given here is some modification to be work,
DB::table('adminUserLogs')
->where('adminUserId', $id)
->where('adminUserOutTime', NULL)
->update(['adminUserOutTime' => \Carbon\Carbon::now()]);
This will result in updating the records where specified conditions. To update specific record pass id
column in where clause of that particular record.
Upvotes: 2