-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65d43cf
commit 551e4a7
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,4 +64,15 @@ protected function updateTimestamps() | |
$this->setAttribute(static::$updated, $now); | ||
} | ||
} | ||
|
||
/** | ||
* Clear the timestamps on this model | ||
* | ||
* @author Ronan Chilvers <[email protected]> | ||
*/ | ||
protected function clearTimestamps() | ||
{ | ||
$this->setAttribute(static::$created, null); | ||
$this->setAttribute(static::$updated, null); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,10 +150,38 @@ public static function qualify($string) | |
*/ | ||
public function __construct() | ||
{ | ||
$this->bootHasTimestamps(); | ||
if ($this->useTimestamps()) { | ||
$this->bootHasTimestamps(); | ||
} | ||
$this->boot(); | ||
} | ||
|
||
/** | ||
* Magic clone method to ensure that cloned models are new | ||
* | ||
* @author Ronan Chilvers <[email protected]> | ||
*/ | ||
public function __clone() | ||
{ | ||
$primaryKey = static::primaryKey(); | ||
if (isset($this->data[$primaryKey])) { | ||
unset($this->data[$primaryKey]); | ||
} | ||
if ($this->useTimestamps()) { | ||
$this->clearTimestamps(); | ||
} | ||
$this->clone(); | ||
} | ||
|
||
/** | ||
* Clone function designed to be overriden by subclasses | ||
* | ||
* | ||
* @author Ronan Chilvers <[email protected]> | ||
*/ | ||
protected function clone() | ||
{} | ||
|
||
/** | ||
* Boot the model | ||
* | ||
|