Php Laravel在索引视图内执行更新/编辑是否可能?

Php Laravel在索引视图内执行更新/编辑是否可能?,php,laravel,bootstrap-modal,Php,Laravel,Bootstrap Modal,是否可以使用索引视图同时使用模式表单执行更新/编辑?我有索引视图,表中显示数据,表中有名为[编辑和删除]的按钮,现在我想在编辑按钮单击后执行编辑/更新,然后会出现模式表单。。?但无论何时使用模态形式,它都会显示错误,如下图所示 这是我的控制器: public function show_setup() { $batch=Batch::all(); return view('setup.show_batch',compact('batch')); } public functi

是否可以使用索引视图同时使用模式表单执行更新/编辑?我有索引视图,表中显示数据,表中有名为[编辑和删除]的按钮,现在我想在编辑按钮单击后执行编辑/更新,然后会出现模式表单。。?但无论何时使用模态形式,它都会显示错误,如下图所示

这是我的控制器:

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-->

批处理
行动
@foreach(批量为$bt)
{{$bt->batch_name}
@endforeach
编辑批
×
{{csrf_field()}}
{{method_字段('PUT')}
学年
接近
保存更改

问题在于,要从集合
$batch
中获取
批次名称
,必须使用javaScript传递所需的数据。需要的数据是
id
批次名称

以下是一个例子:

<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="#" id="editBtn" data-toggle="modal" data-target="#edit_batch" class="btn btn-info btn-sm" data-id="{{ $bt->id }}" data-batch_name="{{ $bt->batch_name }}">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') }}
                    <input id="batch_id" type="hidden" name="id">
                    <div class="form-group">
                        <label>School Year</label>
                        <input id="batch_name" type="text" placeholder="School Year" name="batch_name" class="form-control" autocomplete="off">
                    </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>
</div>
<!--End batch Modal-->

<script type="text/javascript">
    $('.editBtn').on('click',function(e) 
    {
        var link    = $(this);
        batch_id = link.data("id");
        batch_name = link.data("batch_name");
        $("#batch_id").val(batch_id);
        $("#batch_name").val(batch_name);
    });   
</script>

批处理
行动
@foreach(批量为$bt)
{{$bt->batch_name}
@endforeach
编辑批
×
{{csrf_field()}}
{{method_字段('PUT')}
学年
接近
保存更改
$('.editBtn')。在('click',函数(e)上
{
var-link=$(这个);
批次id=链接数据(“id”);
批次名称=链接数据(“批次名称”);
$(“批次id”).val(批次id);
$(“批次名称”).val(批次名称);
});   

是在显示模式时还是在提交表单后?不是,是在我转到url时,它会自动出现错误,但当我删除{{batch_name}}在模式值内,它显示页面,但模式值为空。你能添加你的js代码吗?我没有使用js代码来显示我的代码检查我的更新答案,对于js部分,你可以添加你曾经做过的显示模式的代码:)