File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ protected function getContents(bool $stripTags = false): array
7777 // all versions before this version.
7878 $ versionsBeforeThis = $ this ->newVersion ->previousVersions ()->get ();
7979
80- foreach ($ versionsBeforeThis ->reverse () as $ version ) { // DIFF show previous and current updated data
80+ foreach ($ versionsBeforeThis ->reverse () as $ version ) { // DIFF show previous and current updated data
8181 if (! empty ($ version ->contents )) {
8282 $ oldContents = array_merge ($ oldContents , $ version ->contents );
8383 }
Original file line number Diff line number Diff line change @@ -181,6 +181,11 @@ public function nextVersion(): ?static
181181 ->first ();
182182 }
183183
184+ public function isLatest (): bool
185+ {
186+ return $ this ->getKey () === $ this ->versionable ->latestVersion ()->getKey ();
187+ }
188+
184189 public function diff (?Version $ toVersion = null , array $ differOptions = [], array $ renderOptions = []): Diff
185190 {
186191 if (! $ toVersion ) {
Original file line number Diff line number Diff line change @@ -194,6 +194,18 @@ public function user_can_get_previous_version()
194194 $ this ->assertNull ($ post ->latestVersion ->previousVersion ()->previousVersion ()->previousVersion ());
195195 }
196196
197+ public function user_can_detect_whether_the_version_is_the_latest_version (): void
198+ {
199+ $ post = Post::create (['title ' => 'version1 ' , 'content ' => 'version1 content ' ]);
200+ $ post ->update (['title ' => 'version2 ' ]);
201+ $ post ->update (['title ' => 'version3 ' ]);
202+
203+ $ post ->refresh ();
204+
205+ $ this ->assertTrue ($ post ->latestVersion ->isLatest ());
206+ $ this ->assertFalse ($ post ->latestVersion ->previousVersion ()->isLatest ());
207+ }
208+
197209 /**
198210 * @test
199211 */
You can’t perform that action at this time.
0 commit comments