Skip to content

Get current from a draft? #61

Answered by oddvalue
CNSam asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @CNSam,

You can get the published revision from a draft using the revisions relation and the published scope like this:

$draft->revisions()->published()->first();

If you wanted to do that for a collection of drafts then you could either eager load them when querying or use load on and Eloquent collection.

$draftsCollection->load(['revisions' => fn ($query) => $query->published()]);

There's a section on how relations are handled in the readme https://github.com/oddvalue/laravel-drafts?tab=readme-ov-file#relations

Let me know if you have any other questions.

Thanks!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by oddvalue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants