public function testDeleteTeam() { $this->be($this->getFakeUser()); /** @var Team $team */ $team = factory(Team::class)->create(); $teamId = $team->id; $this->seeInDatabase('teams', ['id' => $team->id, 'club_id' => $team->club_id, 'team' => $team->team])->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$team->id]))->seePageIs(route(self::BASE_ROUTE . '.index'))->seeInElement('#flash-notification .alert.alert-success', 'Team deleted!')->dontSeeInDatabase('teams', ['id' => $teamId]); // Delete team with fixtures /** @var Team $team */ $team = factory(Team::class)->create(); /** @var Fixture $fixture */ $fixture = factory(Fixture::class)->create(['home_team_id' => $team->id]); $this->seeInDatabase('teams', ['id' => $team->id, 'club_id' => $team->club_id, 'team' => $team->team])->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$team->id]))->seePageIs(route(self::BASE_ROUTE . '.index'))->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing fixtures for this team.')->seeInDatabase('teams', ['id' => $team->id, 'club_id' => $team->club_id, 'team' => $team->team]); Fixture::destroy($fixture->id); /** @var Fixture $fixture */ $fixture = factory(Fixture::class)->create(['away_team_id' => $team->id]); $this->seeInDatabase('teams', ['id' => $team->id, 'club_id' => $team->club_id, 'team' => $team->team])->makeRequest('DELETE', route(self::BASE_ROUTE . '.destroy', [$team->id]))->seePageIs(route(self::BASE_ROUTE . '.index'))->seeInElement('#flash-notification .alert.alert-danger', 'Cannot delete because they are existing fixtures for this team.')->seeInDatabase('teams', ['id' => $team->id, 'club_id' => $team->club_id, 'team' => $team->team]); }
/** * Remove the specified resource from storage. * * @param int $id * * @return mixed */ public function destroy($id) { $canBeDeleted = empty(Fixture::find($id)->available_appointments->toArray()); if ($canBeDeleted) { Fixture::destroy($id); \Flash::success('Fixture deleted!'); } else { \Flash::error('Cannot delete because they are existing appointments for this fixture.'); } return redirect('admin/data-management/fixtures'); }