1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/Models/Traits/SerialisesDeletedModels.php

37 lines
830 B
PHP
Raw Normal View History

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