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

simti's avatar
Level 1

pivot table with my custom name

hi.I want to save my quiz scores in database using scores table which has user_id,post_id,correct_num.with laravel name rules its name must be post_user but I've already used this name for comments table. is there anyway that I create this table with my custom name?

0 likes
5 replies
skliche's avatar
skliche
Best Answer
Level 42

Specify another name as the second parameter on the call to belongsToMany().

Edit: And, of course, use that name in your migration file as well.

3 likes
simti's avatar
Level 1

becuz it has a third field,correct_num or it's not neccessary?

skliche's avatar

You don't have to, belongsToMany(...)->withPivot('correct_num') should take care of it.

1 like

Please or to participate in this conversation.