P
P
photosho2016-04-16 20:35:43
Laravel
photosho, 2016-04-16 20:35:43

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

2 answer(s)
D
D', 2016-04-16
@photosho

Can be stored in an intermediate table. Its fields are accessed through the pivot variable.

foreach ($user->tests as $test) {
 var_dump($test->pivot);
}

J
JhaoDa, 2016-04-16
@JhaoDa

You are mistaken, the intermediate table can be used to store extraneous data .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question