【发布时间】:2018-07-16 08:20:40
【问题描述】:
是否可以使用模态表单同时使用索引视图执行更新/编辑?我有 index view 和显示数据的表格,并且在表格内它有名为 [edit and delete] 的按钮现在我想在编辑按钮打开后执行编辑/更新点击然后模态表单会出来..?但是每当使用模态表单时,它都会显示如下错误。
这是我的控制器:
public function show_setup()
{
$batch=Batch::all();
return view('setup.show_batch',compact('batch'));
}
public function edit_batch(request $request)
{
$batch = Batch::find ($request->id);
$batch->batch_name = $request->batch_name;
$batch->save();
return redirect()->back();
}
我的看法
<form>
<div class="form-group">
<table class="table table-hover table-bordered" id="table">
<tr>
<th>Batch</th>
<th>Action</th>
</tr>
@foreach($batch as $bt)
<tr>
<td>{{$bt->batch_name}}</td>
<td>
<a href="#" data-toggle="modal" data-target="#edit_batch" class="btn btn-info btn-sm">Edit </a>
<a href="#" class="btn btn-danger btn-sm">Delete</a>
</td>
</tr>
@endforeach
</table>
</div>
</form> <!-- Modal-->
<div id="edit_batch" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
<div role="document" class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 id="exampleModalLabel" class="modal-title">Edit Batch</h5>
<button type="button" data-dismiss="modal" aria-label="Close" class="close">
<span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<form action="setup/batch/edit" method="POST">
{{csrf_field()}}
{{ method_field('PUT') }}
<div class="form-group">
<label>School Year</label>
<input type="text" placeholder="School Year" name="batch_name" value="{{$batch->batch_name}}" class="form-control" autocomplete="off">
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-secondary">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<!--End batch Modal-->
【问题讨论】:
-
是显示模态时还是提交表单后?
-
不,当我转到 url 时,它会自动出现错误,但是当我删除模态值内的 {{batch_name}} 时,它会显示页面,但模态值是空的..跨度>
-
可以添加你的js代码吗?
-
我没有使用 js 代码,你看到的是我的代码
标签: php laravel bootstrap-modal