Answer the question
In order to leave comments, you need to log in
Where to store additional data in a many-to-many relationship?
Hello. Such a question: there is a testing system where tests created by the administrator are stored in one table, and a list of users is stored in the other. You need to associate users with tests - here, it seems like a many-to-many relationship suggests itself - a separate table that will record the numbers of users and the tests they passed. Seems right?
But you need to know some more data about the tests - for example, when the test was passed by the user, with what result, etc. Where in this situation to store such data? As far as I know, an intermediate table for a many-to-many relationship cannot be used to store extraneous data. Or I'm wrong? If I'm wrong (and if not), how can I implement all this in Laravel?
Answer the question
In order to leave comments, you need to log in
Can be stored in an intermediate table. Its fields are accessed through the pivot variable.
foreach ($user->tests as $test) {
var_dump($test->pivot);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question