Aleks Per
Aleks Per

Reputation: 1639

Laravel update model instead save new

I'm using Laravel 5.1 and I have this code:

$settings = new Setting;
            $settings = $user->settings()->first();
            $settings->user_id = $id;
            $settings->save();

and this code update user model and does not save new. How I can save NEW not update?

Upvotes: 1

Views: 72

Answers (1)

Bharat Geleda
Bharat Geleda

Reputation: 2800

You need to change the name of the variable in which you're fetching the settings like this

$settings_old = $user->settings()->first();
$settings = $settings_old->replicate(); 
$settings->user_id = $id;
$settings->save();

Upvotes: 1

Related Questions