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 a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.