1
0
mirror of https://github.com/flarum/core.git synced 2025-07-05 00:55:35 +02:00
Files
php-flarum/src copy/Core/Support/MergeableTrait.php
2015-07-01 16:31:06 +09:30

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);
}