Put a completed boolean in the pivot table and access it like this.
I think this will work™
$user->quizes()->find($id)->pivot->completed;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey
I'd like some feedback on how to structure something. I'm currently building a quiz and want to be able to do the following:
General Quiz (so that everyone who can access that quiz can complete it as many times as they'd like)
Assigned Quiz (so that you can assign a user to complete the quiz as a one off, but they can also do the same quiz as a general quiz)
So right now I have the General Quiz code working perfectly, no problems there.
I also have code to assign a quiz, but what would be the best way to ensure that they can only complete it once, and only the user who has been assigned the quiz can access it? So far I have a pivot table of:
quiz_id
user_id
So the user can access a quiz that has been assigned to them, but what's the best method to ensure a one-off completion?
I know this is really simple and I can think of some straightforward ways to do this, but I want the code to be clean.
Thanks
Put a completed boolean in the pivot table and access it like this.
I think this will work™
$user->quizes()->find($id)->pivot->completed;
Please or to participate in this conversation.