如何传递数据以从@foreach 编辑模态
How to pass data to edit modal from @foreach
<tbody>
@foreach($courses as $course)
<tr>
<td>{{ $course->course_code }}</td>
<td>{{ $course->course_name }}</td>
<td>{{ $course->description }}</td>
@if(is_null($course->teacher))
<td></td>
@else
<td>{{ $course->teacher->last_name }}, {{ $course->teacher->first_name }}</td>
@endif
<td>
<button type="button" class="assign-modal btn btn-sm btn-success" data-toggle="modal" data-target="#assignModal" data-id="{{ $course->id }}">
<i class="bi bi-person-plus"></i>
</button>
</td>
</tr>
@endforeach
这是我的tablebody
<!-- Assign Modal -->
<div class="modal fade" id="assignModal" tabindex="-1" role="dialog" aria-labelledby="assignModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="assignModalLabel">Assign Teacher</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
@if(!empty($course->id))
<form method="POST" action={{ route('courses.update', $course->id) }}>
@csrf
@method('PUT')
<input type="text" class="form-control" name="id" value="" id="course-id" hidden="">
<select class="form-control select-teacher" style="widht: 100%" name="teacher_id">
@foreach($teachers as $teacher)
<option value="{{ $teacher->id }}">{{ $teacher->last_name }}, {{ $teacher->first_name }}</option>
@endforeach
</select>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Assign</button>
</div>
</form>
@endif
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
这是我的模态框。
显然,它在昨天之前工作正常,但它不再工作了。
我的代码现在的问题是只有最后一列数据是 editable。如何修改其他列的值?
每个模式必须有一个特定的 id,尝试将 {{ $course->id }} 添加到标签 id 和 aria-labelledby 属性
<div class="modal fade" id="assignModal{{ $course->id }}" tabindex="-1" role="dialog" aria-labelledby="assignModalLabel{{ $course->id }}" aria-hidden="true">
前面的代码也必须在 foreach loop
中作为 tbody
中的第一个代码
@foreach($courses as $course)
<div class="modal fade" id="assignModal{{ $course->id }}" tabindex="-1" role="dialog" aria-labelledby="assignModalLabel{{ $course->id }}" aria-hidden="true">
...
</div>
@endforeach
并且还像以前一样更新模态标签中的所有 id
id 必须是唯一的。
并且还更新如下以将按钮附加到特定的 id
<button type="button" class="assign-modal btn btn-sm btn-success" data-toggle="modal" data-target="#assignModal{{ $course->id }}" data-id="{{ $course->id }}">
<tbody>
@foreach($courses as $course)
<tr>
<td>{{ $course->course_code }}</td>
<td>{{ $course->course_name }}</td>
<td>{{ $course->description }}</td>
@if(is_null($course->teacher))
<td></td>
@else
<td>{{ $course->teacher->last_name }}, {{ $course->teacher->first_name }}</td>
@endif
<td>
<button type="button" class="assign-modal btn btn-sm btn-success" data-toggle="modal" data-target="#assignModal" data-id="{{ $course->id }}">
<i class="bi bi-person-plus"></i>
</button>
</td>
</tr>
@endforeach
这是我的tablebody
<!-- Assign Modal -->
<div class="modal fade" id="assignModal" tabindex="-1" role="dialog" aria-labelledby="assignModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="assignModalLabel">Assign Teacher</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
@if(!empty($course->id))
<form method="POST" action={{ route('courses.update', $course->id) }}>
@csrf
@method('PUT')
<input type="text" class="form-control" name="id" value="" id="course-id" hidden="">
<select class="form-control select-teacher" style="widht: 100%" name="teacher_id">
@foreach($teachers as $teacher)
<option value="{{ $teacher->id }}">{{ $teacher->last_name }}, {{ $teacher->first_name }}</option>
@endforeach
</select>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Assign</button>
</div>
</form>
@endif
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
这是我的模态框。
显然,它在昨天之前工作正常,但它不再工作了。 我的代码现在的问题是只有最后一列数据是 editable。如何修改其他列的值?
每个模式必须有一个特定的 id,尝试将 {{ $course->id }} 添加到标签 id 和 aria-labelledby 属性
<div class="modal fade" id="assignModal{{ $course->id }}" tabindex="-1" role="dialog" aria-labelledby="assignModalLabel{{ $course->id }}" aria-hidden="true">
前面的代码也必须在 foreach loop
中作为 tbody
@foreach($courses as $course)
<div class="modal fade" id="assignModal{{ $course->id }}" tabindex="-1" role="dialog" aria-labelledby="assignModalLabel{{ $course->id }}" aria-hidden="true">
...
</div>
@endforeach
并且还像以前一样更新模态标签中的所有 id id 必须是唯一的。
并且还更新如下以将按钮附加到特定的 id
<button type="button" class="assign-modal btn btn-sm btn-success" data-toggle="modal" data-target="#assignModal{{ $course->id }}" data-id="{{ $course->id }}">