Laravel: update vs fill

Let’s take a look at the difference between update and fill of Eloquent methods.

When using update, it does persist the changes immediately in the database, for example:

update(['first_name' => 'Imran', 'last_name' => 'Khan']);

On the other hand, let’s say if we don’t want to update record immediately, but set user to active before saving then fill() would be the handy option.

$user = User::find(1); 
$user->fill(['first_name' => 'Imran', 'last_name' => 'Khan']); 

$user->is_active = true; 
$user->save();

Register Or Login to leave a comment.