1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Models/Traits/SerialisesDeletedModels.php
2019-01-30 22:25:37 +11:00

37 lines
830 B
PHP

<?php
namespace App\Models\Traits;
use Illuminate\Contracts\Database\ModelIdentifier;
/**
* Class SerialisesDeletedModels
* @see https://github.com/laravel/framework/issues/9347#issuecomment-165647596
*/
trait SerialisesDeletedModels
{
/**
* @param $value
* @return mixed
*/
protected function getRestoredPropertyValue($value)
{
if (!$value instanceof ModelIdentifier) {
return $value;
}
if (is_array($value->id)) {
return $this->restoreCollection($value);
}
$instance = new $value->class;
$query = $instance->newQuery()->useWritePdo();
if (property_exists($instance, 'forceDeleting')) {
return $query->withTrashed()->find($value->id);
}
return $query->findOrFail($value->id);
}
}