Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

emil2709's avatar

Pass data to a many to many database

I got 3 tables user , visit and then user_visit (many to many). I want to make a user, and when i add a user i also want to update the visit table (and user_visit ofc.) So how will my controller look like? My views and model is all right, i only need to see how the Controller will look like :)

Anyone know, or know a video/text where i can learn it?

0 likes
1 reply
Lars-Janssen's avatar

If you have the right relations you could do it like this:

public function store()
{
    $user->visit()->attach($visitId);
}
1 like

Please or to participate in this conversation.