16
16
use Illuminate \Support \Facades \DB ;
17
17
18
18
/**
19
- * @property-read int $id
20
- * @property int $subject_id
19
+ * @property-read positive- int $id
20
+ * @property positive- int $subject_id
21
21
* @property string $subject_type
22
- * @property Model $stored_attributes
22
+ * @property array $stored_attributes
23
23
* @property string $version
24
24
* @property SnapshotOptions|array $options;
25
- * @property-read Carbon $created_at
26
- * @property-read Carbon $updated_at
25
+ * @property Carbon $created_at
26
+ * @property Carbon $updated_at
27
+ * @property-read Model $subject
27
28
*/
28
29
class Snapshot extends Model implements SnapshotContract
29
30
{
@@ -65,9 +66,7 @@ public function toModel(bool $fillExcludedAttributes = false): Model
65
66
{
66
67
if ($ fillExcludedAttributes ) {
67
68
/** @var Model $model */
68
- $ model = ($ this ->relationLoaded ('subject ' )
69
- ? $ this ->getRelation ('subject ' ) : $ this ->subject ()->firstOrFail ()
70
- )->replicate ();
69
+ $ model = $ this ->subject ->replicate ();
71
70
} else {
72
71
/** @var Model $model */
73
72
$ model = new ($ this ->getAttribute ('subject_type ' ));
@@ -82,7 +81,7 @@ public function revert(): Model
82
81
{
83
82
/** @var Model $model */
84
83
$ model = DB ::transaction (function () {
85
- $ model = $ this ->relationLoaded ( ' subject ' ) ? $ this -> getRelation ( ' subject ' ) : $ this -> subject ()-> firstOrFail () ;
84
+ $ model = $ this ->subject ;
86
85
$ model ->setRawAttributes ($ this ->getAttribute ('stored_attributes ' ));
87
86
$ model ->save ();
88
87
@@ -105,9 +104,7 @@ public function branch(): Model
105
104
{
106
105
/** @var Model $model */
107
106
$ model = DB ::transaction (function () {
108
- $ model = ($ this ->relationLoaded ('subject ' )
109
- ? $ this ->getRelation ('subject ' ) : $ this ->subject ()->firstOrFail ()
110
- )->replicate ();
107
+ $ model = $ this ->subject ->replicate ();
111
108
$ model ->setRawAttributes ($ this ->getAttribute ('stored_attributes ' ));
112
109
$ model ->save ();
113
110
@@ -130,9 +127,7 @@ public function branch(): Model
130
127
131
128
public function fork (): Model
132
129
{
133
- $ model = ($ this ->relationLoaded ('subject ' )
134
- ? $ this ->getRelation ('subject ' ) : $ this ->subject ()->firstOrFail ()
135
- )->replicate ();
130
+ $ model = $ this ->subject ->replicate ();
136
131
$ model ->setRawAttributes ($ this ->getAttribute ('stored_attributes ' ));
137
132
$ model ->save ();
138
133
0 commit comments