mirror of
https://github.com/flarum/core.git
synced 2025-07-05 00:55:35 +02:00
24 lines
510 B
PHP
24 lines
510 B
PHP
<?php namespace Flarum\Core\Models;
|
|
|
|
trait MergeableTrait
|
|
{
|
|
public function saveAfter(Model $previous)
|
|
{
|
|
if ($previous instanceof static) {
|
|
if ($merged = $this->mergeInto($previous)) {
|
|
$merged->save();
|
|
return $merged;
|
|
} else {
|
|
$previous->delete();
|
|
return $previous;
|
|
}
|
|
}
|
|
|
|
$this->save();
|
|
|
|
return $this;
|
|
}
|
|
|
|
abstract protected function mergeInto(Model $previous);
|
|
}
|