/** * @depends testCreateEmptyProject * @param Project $project */ function testProjectUserAssignment(Project $project) { $user = factory(User::class)->create(); // attaching $project->team()->attach($user); $this->assertFalse($project->team()->get()->isEmpty()); $user = $project->team()->get()->get(0); $this->assertEquals('member', $user->pivot->role); // detaching $project->team()->detach($user); $this->assertTrue($project->team()->get()->isEmpty()); }
/** * Update the role of the selected member * * @param Request $request * @param Project $project * @param User $user */ public function update(Request $request, Project $project, User $user) { $role = $request->input('role', 'member'); $project->team()->updateExistingPivot($user->id, ['role' => $role]); return $user; }