Support the ongoing development of Laravel.io →
Database Eloquent Laravel
Last updated by @tvbeek 3 months ago.
0
moderator

Hello @tobisch1591,

From the documentation:

To determine the table name of the relationship's intermediate table, Eloquent will join the two related model names in alphabetical order. However, you are free to override this convention. You may do so by passing a second argument to the belongsToMany method:

With that convention the table should be named language_user but it is possible to change it.

I suspect you have a method languages on your user model, there you can add the table as second argument.

public function languages()
{
    return $this->belongsToMany(Language::class, 'user_language');
}

I think that is enough to help you (and if you have defined the relation on your Language model you can also use the second parameter on that place.)

Ps. I have updated your post to make the code blocks more readable.

0

Sign in to participate in this thread!

LoadForge

Your banner here too?

Tobias tobisch1591 Joined 8 Oct 2022

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.

© 2023 Laravel.io - All rights reserved.