Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9294147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:18:11+00:00 2026-06-18T21:18:11+00:00

How can I update multiple fields in an Eloquent model? Let’s say I got

  • 0

How can I update multiple fields in an Eloquent model? Let’s say I got it like this:

$user = User::where("username", "=", "rok");

And then I have all these model parameters:

$new_user_data = array("email" => "rok@rok.com", "is_superuser" => 1, ...);

I can’t just do:

$user->update($new_user_data);

What’s the proper way? I hope not a foreach.

The following does work, however. Is this the way to go?

User::where("id", "=", $user->id)->update($new_user_data);

The problem with the last one (besides it being clunky) is that when using it from an object context, the updated fields are not visible in the $this variable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:18:12+00:00Added an answer on June 18, 2026 at 9:18 pm

    The method you’re looking for is fill():

    $user = User::where ("username","rok"); // note that this shortcut is available if the comparison is =
    $new_user_data = array(...);
    $user->fill($new_user_data);
    $user->save();
    

    Actually, you could do $user->fill($new_user_data)->save(); but I find the separate statements a little easier to read and debug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I update multiple values in MySQL? This didn't work: UPDATE test SET
Using CakePHP's Ajax based observefield, I would like to update multiple fields, into my
I have a scenario where I would like to update multiple fields in multiple
How can update a input hidden inside an UpdatePanel on an AsyncPostBack? The user
I was wondering how GMail and things like that can update the emails in
I have this problem that I have multiple fields that updates a database via
I have to fill in multiple form fields on a web page I got
I can't work out what the appropriate model structure should be for this problem
I've got a Rails project which has a car model and it has multiple
Let's say I have a table named transaction with transaction_date, deposit, withdrawal fields. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.