From 47c5827ff871022630b317805e43ef8061e4f1ab Mon Sep 17 00:00:00 2001 From: Keith McGahey Date: Thu, 2 Aug 2018 11:23:52 +1000 Subject: [PATCH] Add latest revision function to posts Function used for previewing posts and pages --- src/Enpress/Models/Post.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Enpress/Models/Post.php b/src/Enpress/Models/Post.php index 2ffbdbf..e484101 100644 --- a/src/Enpress/Models/Post.php +++ b/src/Enpress/Models/Post.php @@ -300,5 +300,14 @@ public static function root($name) ->where('post_parent', 0) ->firstOrFail(); } + + public function latestRevision() + { + return $this->withoutGlobalScopes() + ->type('revision') + ->where('post_parent', $this->id) + ->orderBy('post_modified', 'desc') + ->first(); + } }