我想將註冊用戶的ID發送到模式,以便能夠直接從模式編輯DB,但由於它是模式而不是其他頁面,所以我無法使用路由方法。而且我不知道是否有可能使用JavaScript傳遞id以實現模式laravel
這裏是我的視圖代碼:
table class="highlight responsive-table">
<thead>
<tr>
<th data-field="id" hidden>ID</th>
<th data-field="name">Nombre</th>
<th data-field="last_name">Apellidos</th>
<th data-field="course">Curso</th>
{{-- <th data-field="date">Fecha</th> --}}
<th style="text-align: right;">Acciones</th>
</tr>
</thead>
<tbody>
@foreach($professors as $professor)
<tr>
<td hidden>{{$professor->id}}</td>
<td>{{$professor->name}}</td>
<td>{{$professor->last_name}}</td>
<td>{{$professor->course}}</td>
<td style="text-align: right; width: 20em">
<button data-target="modalEdit" class="waves-effect waves-light btn yellow darken-2"><i class="material-icons left" style="margin:0">create</i></button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
<!-- Modal Structure -->
<div id="modalEdit" class="modal modal-fixed-footer">
<form class="col s12" method="POST" action="/professors">
<div class="modal-content">
<h4>Editar a {{ $professor->name }}</h4>
{{csrf_field()}}
<div class="row">
<div class="input-field col s6">
<input id="name" name="name" type="text" class="validate" required>
<label for="first_name">Nombre</label>
</div>
<div class="input-field col s6">
<input id="last_name" name="last_name" type="text" class="validate" required>
<label for="last_name">Apellidos</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="course" name="course" type="text" class="validate" required>
<label for="course">Nombre de curso</label>
</div>
</div>
<div class="file-field input-field">
<div class="btn btn yellow darken-2">
<span>Subir foto</span>
<input type="file">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
<p>Nota: Porás actualizar la foto usando el botón editar.</p>
</div>
<div class="modal-footer">
<button type="submit" class="waves-effect waves-light btn blue darken-2 ">Registrar</button>
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Cerrar</a>
</div>
</form>
<script>
$(document).ready(function(){
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('#modalEdit').modal();
});
</script>
我需要ID傳遞給模態得到的資訊用戶來自數據庫。
你打算在類'darken-2'上點擊''按鈕'來打開'modal'嗎? – eeya
確切地說,模態實際上是打開的,因爲我沒有傳遞任何數據,模態是空的。 –