| @@ 94-107 (lines=14) @@ | ||
| 91 | * Original sync doesn't insert NULL ids |
|
| 92 | * @param $fighters |
|
| 93 | */ |
|
| 94 | public function syncTeams($fighters) |
|
| 95 | { |
|
| 96 | $this->teams()->detach(); |
|
| 97 | foreach ($fighters as $fighter) { |
|
| 98 | if ($fighter != null) { |
|
| 99 | $this->teams()->attach($fighter); |
|
| 100 | } else { |
|
| 101 | // Insert row manually |
|
| 102 | DB::table('round_team')->insertGetId( |
|
| 103 | ['team_id' => null, 'round_id' => $this->id] |
|
| 104 | ); |
|
| 105 | } |
|
| 106 | } |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * Supercharge of sync Many2Many function. |
|
| @@ 114-126 (lines=13) @@ | ||
| 111 | * Original sync doesn't insert NULL ids |
|
| 112 | * @param $fighters |
|
| 113 | */ |
|
| 114 | public function syncCompetitors($fighters) |
|
| 115 | { |
|
| 116 | $this->competitors()->detach(); |
|
| 117 | foreach ($fighters as $fighter) { |
|
| 118 | if ($fighter != null) { |
|
| 119 | $this->competitors()->attach($fighter); |
|
| 120 | } else { |
|
| 121 | DB::table('round_competitor')->insertGetId( |
|
| 122 | ['competitor_id' => null, 'round_id' => $this->id] |
|
| 123 | ); |
|
| 124 | } |
|
| 125 | } |
|
| 126 | } |
|
| 127 | } |
|