I'm trying to save into the database but I constantly get this error
Call to undefined method stdClass::save()
my controller
$c = DB::table('subject_user')->where('user_id', $value)->first();
$c->auth_teacher = '1';
$c->save();
Try this approach
I haven't try save
method with where
condition. Hopefully, this approach may solve your problem.
DB::table('subject_user')->where('user_id', $value)->update(['auth_teacher' => 1]);
I just ran into the same problem and figured out the real Laravel answer.
The answer you've accepted here (https://stackoverflow.com/a/41051946/470749) doesn't follow the truest Laravel way.
When I re-read the docs at https://laravel.com/docs/5.4/eloquent#retrieving-models, I noticed that ->save()
will work only if the way that I retrieved the object(s) was via the model like this:
$flights = App\Flight::where('active', 1)
->orderBy('name', 'desc')
->take(10)
->get();
There is no need to use DB::table()
anywhere, and using it doesn't seem to be the recommended way.
So, you could change DB::table('subject_user')->where
to App\Subject_user::where
(or whatever is appropriate for you).
DB::table('subject_user')->where('user_id', $value)->update(['auth_teacher' => 1]);
I have been able to succeed with this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With