Last active
August 26, 2021 13:08
-
-
Save rstriquer/2bf8fb693fdd5cb868489ad937dda370 to your computer and use it in GitHub Desktop.
update model illuminate eloquent (laravel database)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# once i come accross this, seams to be a good thing to remember .. | |
# it creates a new record on database table and automatically replace objects attributes with the new created record | |
class fooModel | |
{ | |
public function create(array $data) | |
{ | |
if (!isset($data['id'])) { | |
$data['id'] = rand(0,999); | |
} | |
$new = new static; | |
$new = parent::create($data); | |
$this->attributes = $new->attributes; | |
$this->original = $new->original; | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment