Update RoomController.php
Fix controller - set room id for auditions when creating room 0
This commit is contained in:
parent
c2572414e6
commit
3cb837fa66
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Audition;
|
||||||
use App\Models\BonusScoreDefinition;
|
use App\Models\BonusScoreDefinition;
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
|
@ -27,6 +28,12 @@ class RoomController extends Controller
|
||||||
]);
|
]);
|
||||||
$unassignedRoom->id = 0;
|
$unassignedRoom->id = 0;
|
||||||
$unassignedRoom->save();
|
$unassignedRoom->save();
|
||||||
|
|
||||||
|
$auditionsToUpdate = Audition::where('room_id', null)->get();
|
||||||
|
foreach ($auditionsToUpdate as $audition) {
|
||||||
|
$audition->room_id = 0;
|
||||||
|
$audition->save();
|
||||||
|
}
|
||||||
$rooms = Room::with('auditions.entries', 'entries')->orderBy('name')->get();
|
$rooms = Room::with('auditions.entries', 'entries')->orderBy('name')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +47,8 @@ class RoomController extends Controller
|
||||||
$rooms = Room::with(['judges.school', 'auditions'])->get();
|
$rooms = Room::with(['judges.school', 'auditions'])->get();
|
||||||
$bonusScoresExist = BonusScoreDefinition::count() > 0;
|
$bonusScoresExist = BonusScoreDefinition::count() > 0;
|
||||||
|
|
||||||
return view('admin.rooms.judge_assignments', compact('usersWithoutRooms', 'usersWithRooms', 'rooms', 'bonusScoresExist'));
|
return view('admin.rooms.judge_assignments',
|
||||||
|
compact('usersWithoutRooms', 'usersWithRooms', 'rooms', 'bonusScoresExist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateJudgeAssignment(Request $request, Room $room)
|
public function updateJudgeAssignment(Request $request, Room $room)
|
||||||
|
|
@ -119,7 +127,8 @@ class RoomController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($room->auditions()->count() > 0) {
|
if ($room->auditions()->count() > 0) {
|
||||||
return redirect()->route('admin.rooms.index')->with('error', 'Cannot delete room with auditions. First move the auditions to unassigned or another room');
|
return redirect()->route('admin.rooms.index')->with('error',
|
||||||
|
'Cannot delete room with auditions. First move the auditions to unassigned or another room');
|
||||||
}
|
}
|
||||||
|
|
||||||
$room->delete();
|
$room->delete();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue