Search code examples
laravellaravel-5.7laravel-authenticationupdatemodel

Laravel | Updating the Logged-In User - save() vs update()


I want to update a field of the logged-in user.

In my controller, this works:

Auth::user()->the_field = $theField;
Auth::user()->save();

This doesn't:

Auth::user()->update(['the_field' => $theField]);

I would expect this to work since similar code (updating an order for example) works fine. Something like:

$order->update(['order_status' => OrderStatus::ORDER_COMPLETED]);

So why is it not working? Am I doing something wrong?


Solution

  • You have to add fields you want to update in $fillable property User Model when using create or update Method. Based on Laravel Documentation

    protected $fillable = [
           
         'the_field'
    ];