2

I'm replicating a database row and want to return the new row as an object.

$new_foo = Foo::find($id)->replicate()->save();
print_r($new_foo);

This returns 1 instead of the new object I just created. Thoughts?

americanknight
  • 689
  • 3
  • 18
  • 37

1 Answers1

5

In your code, you are actually saving the value returned from the save() method and not the replicated model.

You need to make a slight change to your code to save the replicated model into $new_foo

$new_foo = Foo::find($id)->replicate();
$new_foo->save();
dd($new_foo);

save() method returns boolean.

Noman Ur Rehman
  • 6,707
  • 3
  • 24
  • 39
Limon Monte
  • 52,539
  • 45
  • 182
  • 213