I try to get the selected option for the Team select on my form to further use it in the same form to limit the available positions in the selected team.
I managed to limit each team, so that it has a maximum of 9 players.
The idea is to have +-2 players on each position( 2 forward, 2 center, 2 back, 3 substitutes) for each team, if the spots are full the 'position' (ex. forward) option doesn't show up for the selected team.
Might be helpful : I am using foreign keys : (player -> one position_id, team -> many players)
My positions table is consisted of id, name and max and it is passed as $positions
I am trying to figure out a way, i am new to the subject so if you guys can help me, would be a great.
Or tell me if it isn't possible.
Thanks in advance.
<form action="/player" method="POST" enctype="multipart/form-data" class="form-control">
@csrf
...
<div class="mb-3">
<select name="team_id">
<option selected>Select Team</option>
@foreach ($teams as $team)
@if ($team->players->count() < 9)
<option value="{{ $team->id }}">{{ $team->name }}</option>
@endif
@endforeach
</select>
</div>
<div class="mb-3">
<select name="position_id">
<option selected>Select Position</option>
@foreach ($teams as $team)
@if ($team->id == ???)
@foreach ($positions as $position)
@if ($position->count() > $position->max)
<option value="{{ $position->id }}" disabled>{{ $position->name }}</option>
@else
<option value="{{ $position->id }}">{{ $position->name }}</option>
@endif
@endforeach
@endif
@endforeach
</select>
</div>
...
<button type="submit" class="btn btn-primary">submit</button>
</form>
```