laravel_blog_image

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:

<?php 
$user = User::find(1); 
 
// This will update the record immediately
$user->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();
Author: Danyal
I'm skilled programmer with expertise in Vue.js/Nux.js for front-end development and PHP Laravel for back-end development. I excel in building APIs and services, and also have experience in web server setup & maintenance. My versatile skill set allows you to develop and maintain web applications effectively, from the user interface to the server-side functionality. I love coding with never ending learning attitude, thanks for visiting danya.dk