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

Please show all your models and your tag() execution. And whats the name of the m:n-table?

Last updated 8 years ago.
0

For some "magic", call your relation table tag_user. This way Eloquent will find it on its own.

For setting your relations in the models, use belongsToMany in both models.

// In User model
public function tag()
{
    return $this->belongsToMany('App\Tag');
}
// In Tag model
public function user()
{
    return $this->belongsToMany('App\User');
}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

sEnkaaa senkaaa Joined 26 Jun 2016

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.