Closed etcware closed 2 years ago
The many to many table name is groups_users.
You can easily save relations like this $user->save($group)
.
$user->firstname = $this->request->getPost('firstname');
$user->lastname = $this->request->getPost('lastname');
$user->name = $this->request->getPost('name');
$user->email = $this->request->getPost('email');
$user->password = $this->request->getPost('password');
$user->password_hash = $this->request->getPost('password');
$user->password_confirm = $this->request->getPost('password_confirm');
$user->activate_hash = random_string('alnum', 32);
$group_id = $this->request->getPost('group');
if (is_numeric($group_id)) {
$user->groups = $groupModel->find($group_id);
if (! $userModel->save($user)) {
return redirect()->back()->withInput()->with('errors', $userModel->errors());
}
**$user->save($user->groups);**
}
It will automatically guess the table name groups_users
and add a row without any GroupsUserModel and GroupsUser(Entity) classes required.
great!
I know that this is not the correct way to communicate, but I need another suggestion. May be useful to insert these suggestions in documentation... I have an UserModel with the classical relationship many to many
And the symmetrical GroupModel with
When I save a user may I save also a group relation? That is a row in users_groups?