Support the ongoing development of →
Database Eloquent Laravel
Last updated by @tvbeek 1 year ago.

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.


Sign in to participate in this thread!


Your banner here too?

Tobias tobisch1591 Joined 8 Oct 2022


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

Your logo here?

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

© 2024 - All rights reserved.