-
Hil folks, Not sure if im losing the plot here but ultimately I have an authors model of which I've assigned and setup the HasDrafts trait. What I want to know or figure out is how I can then get from a list of "only draft" records, the current, live/published record? Secondly, to save me having to open a seperate discussion, how do relationships work. I was hoping that if I created a draft, the relationships would clone (and add any new relationships) to that draft, is that not the case? So if I edited a record of an author, and we linked them to a new category of say "sport" how would this work? Tia! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 $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! |
Beta Was this translation helpful? Give feedback.
Hey @CNSam,
You can get the published revision from a draft using the revisions relation and the published scope like this:
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.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!