I have 3 tables:
1 | Men >80kg
2 | Women >80kg
3 | Team Men >80kg
Category_Tournament (List all categories available in a tournament)
Category_Tournament_User (categories registered by user)
Category is the list of categories for all tournaments (C for abreviation)
Category_Tournament is the list of categories the admin configured for this tournament (CT for abreviation)
Category_tournament_User is the categories the user has registred (CTU for abreviation)
User has a list of checkbox that I need to sync with:
$tournament->categories_user()->sync($categories);
In Tournament Model, I have:
public function categories_user()
{
return $this->belongsToMany('App\Category','category_tournament_user', 'user_id', 'category_tournament_id')
->withTimestamps();
}
Thing is data is syncing in CTU, but instead of inserting user_id, it insert tournament_id.
It probably does it because I'm in Tournament Model.
I tried to put the relationship in User Model, but couldn't make it work neither
try this
$tournament->user_categories->sync($userCategories, [
'category_id' => $category_id
.....
....
]);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community