@@ -94,7 +94,11 @@ protected function newRevision(): void
94
94
95
95
$ revision = $ this ->fresh ()?->replicate();
96
96
97
- static ::saved (function () use ($ revision ) {
97
+ static ::saved (function (Model $ model ) use ($ revision ): void {
98
+ if ($ model ->isNot ($ this )) {
99
+ return ;
100
+ }
101
+
98
102
$ revision ->created_at = $ this ->created_at ;
99
103
$ revision ->updated_at = $ this ->updated_at ;
100
104
$ revision ->is_current = false ;
@@ -126,22 +130,24 @@ public function setCurrent(): void
126
130
{
127
131
$ oldCurrent = $ this ->revisions ()->withDrafts ()->current ()->excludeRevision ($ this )->first ();
128
132
129
- static ::saved (function () use ($ oldCurrent ) {
130
- if ($ oldCurrent ) {
131
- $ oldCurrent ->{$ this ->getIsCurrentColumn ()} = false ;
132
- $ oldCurrent ->timestamps = false ;
133
- $ oldCurrent ->saveQuietly ();
133
+ static ::saved (function (Model $ model ) use ($ oldCurrent ): void {
134
+ if ($ model ->isNot ($ this ) || ! $ oldCurrent ) {
135
+ return ;
134
136
}
137
+
138
+ $ oldCurrent ->{$ this ->getIsCurrentColumn ()} = false ;
139
+ $ oldCurrent ->timestamps = false ;
140
+ $ oldCurrent ->saveQuietly ();
135
141
});
136
142
137
143
$ this ->{$ this ->getIsCurrentColumn ()} = true ;
138
144
}
139
145
140
146
public function setLive (): void
141
147
{
142
- $ published = $ this ->revisions ()->excludeRevision ( $ this )-> published ()->first ();
148
+ $ published = $ this ->revisions ()->published ()->first ();
143
149
144
- if (! $ published ) {
150
+ if (! $ published || $ this -> is ( $ published ) ) {
145
151
$ this ->{$ this ->getPublishedAtColumn ()} ??= now ();
146
152
$ this ->{$ this ->getIsPublishedColumn ()} = true ;
147
153
$ this ->setCurrent ();
@@ -157,7 +163,11 @@ public function setLive(): void
157
163
$ published ->forceFill ($ newAttributes );
158
164
$ this ->forceFill ($ oldAttributes );
159
165
160
- static ::saved (function () use ($ published ) {
166
+ static ::saved (function (Model $ model ) use ($ published ): void {
167
+ if ($ model ->isNot ($ this )) {
168
+ return ;
169
+ }
170
+
161
171
$ published ->{$ this ->getIsPublishedColumn ()} = true ;
162
172
$ published ->{$ this ->getPublishedAtColumn ()} ??= now ();
163
173
$ published ->setCurrent ();
0 commit comments