Mikegk
6 months ago
1144
4
Eloquent

Update Eloquent Data

Posted 6 months ago by Mikegk

Hi Guys,

within an model (UserStatus), I have the following method:

private static function getUserStatusById($id_user,$select='*'){
        return UserStatus::where('id_user',$id_user)
                            ->select($select)
                            ->limit(1)
                            ->get();
    }

This results the wanted row as it should. But I wonder why I cannot change the data inside the model:

someMethod(){
...
$user_status = UserStatus::getUserStatusById($id_user,$select);
        $user_status->something = 1;
        $user_status->save();
}

...Results in: "Method Illuminate\Database\Eloquent\Collection::save does not exist."

Using

$user_status = UserStatus::find(1)
$user_status->something = 1;
$user_status->save();

...works fine. Why?

Please sign in or create an account to participate in this conversation.