/** * Test un-following a project by checking database deletion and viewing injections */ public function testUnFollow() { \App\ProjectFollower::create(['user_id' => $this->user2->id, 'project_id' => $this->project->id]); $this->actingAs($this->user2)->visit($this->project->getSlug())->press('follow-remove')->seePageIs($this->project->getSlug())->dontSeeInDatabase('project_followers', ['user_id' => $this->user2->id])->see('You are now not following this project.')->see('follow-add'); //Remove follower $this->project->followers()->delete(); }
/** * Adds a follower to the project * * @param Int user_id * @return new follower object */ public function addFollower($user_id = null) { if ($user_id == null) { $user_id = Auth::user()->id; } $follower = ProjectFollower::create(['user_id' => $user_id, 'project_id' => $this->id]); return $this->followers()->save($follower); }