Support the ongoing development of Laravel.io →
Eloquent Database
Last updated 2 years ago.
0

Your database naming convention goes against the naming convention of Laravel, which is likely to make your life more difficult than it needs to be. If you're working with existing infrastructure, you can't do much about it, but if you're working on a new project, it's definitely something to consider. :)

For a many to many relationship, you need the two things that relate to each other many-to-many style, and a pivot table.

In this case, it looks like you want to associate many tournaments with many users, using participants as a pivot table. However, it looks like your pivot table is not named as expected, so Laravel isn't able to find it.

I've never personally had to deal with this situation, but I believe you need to use ->using on your relationship and point to an intermediate model if you deviate from the expected convention. In this case, it looks like you'd want a participant intermediate/pivot model.

See this section of the docs, specifically the section titled "Defining Custom Intermediate Table Models" for some (hopefully) useful information.

EDIT:

My apologies, I missed what's likely the most important bit of your post (you're referencing your pivot table directly in the belongsToMany constructor). Give me a few and I'll check this a bit more closely. :)

Further edit:

Alright, found your trouble. It's the non-standard naming convention of your columns. You need to reference both the parent key and related key if they aren't "id". This should get you sorted: $this->belongsToMany(User::class, 'Participants', 'Id_tourn', 'Id_user', 'Id', 'Id');

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Viktor luntik4344 Joined 7 Nov 2018

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.