mp3man's avatar

Updating table using fill() method doesn't works

Hi, I've the next code:

$user->fill(['password' => $hashPassword]);

in which $user is ans instance fot from a User::find($request->user) that returns the correct user model. I've too the filalble protected property in my model as follows:

protected $fillable = [
        'niu',
        'password',
    ];

Does anyone knows why the database is never updated with this password?

Thanks!

0 likes
5 replies
itsfg's avatar

Is that all your code ? fill() just fill your object, it doesn't save it to the database. Do you call save() after that ?

mp3man's avatar

That was another solution to instead use update() method directly. The problem is that I was looking at the official Laravel documentation and the Elloquent section, don't mentions the update() method due this is explained in database section. Thanks!

mp3man's avatar

Solved! I've found in this webpage that fill() method is not persisent in DB, as the update() yes it is

itsfg's avatar

Good ! Yes using update() is another way to go. Don't forget to mark the thread as resolved.

mp3man's avatar

Don't know how to mark as solved

Please or to participate in this conversation.