无法提交Laravel 5.6表格

时间:2019-01-09 11:15:27

标签: php laravel-5.6

我正在显示一个项目列表,每个项目都有一个编辑按钮,单击该按钮会弹出一个模态,效果很好

@foreach ($testimonials as $item)
<tr class="text-muted">
    <td class="text-capitalize">{{ $item->firstname }}</td>
    <td class="text-capitalize">{{ $item->lastname }}</td>
    <td>{{ $item->comment }}</td>
    <td class="text-capitalize">@if ($item->status === 0) hidden @else showing @endif</td>
    <td>
        <button type="button" class="btn-custom-one" data-toggle="modal" data-target="#editTestimonial{{$item->id}}">Edit</button> 
    </td>
</tr>

{{-- Edit Modal --}}
<div class="modal fade" id="editTestimonial{{$item->id}}" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <form action="/home/testimonials/{{$item->id}}/update" method="POST">
                    @method('PUT')
                    @csrf
                    <div class="form-row">
                        <div class="form-group col-lg-6">
                            <label for="firstname">Firstname</label>
                            <input type="text" name="firstname" value="{{$item->firstname}}" class="form-control" aria-describedby="firstname">
                            <small id="firstname" class="text-muted">Firstname</small>
                        </div>

                        <div class="form-group col-lg-6">
                            <label for="lastname">Lastname</label>
                            <input type="text" name="lastname" value="{{$item->lastname}}" class="form-control" aria-describedby="lastname">
                            <small id="lastname" class="text-muted">Lastname</small>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="comment">Comment</label>
                        <textarea name="comment" class="form-control" cols="30" rows="5" aria-describedby="comment">{{$item->comment}}</textarea>
                        <small id="comment" class="text-muted">Client's comment</small>
                    </div>

                    <button type="submit" class="btn btn-custom-two">Save</button>
                </form>
            </div>
        </div>
    </div>
</div>
@endforeach

更新路径为Route::put('/home/testimonials/{testimonial}/update', 'TestimonialController@update');

TestimonialController更新功能现在就像这样

public function update(Request $request, Testimonial $testimonial)
{
dd($request)
}

现在的问题是,单击“保存”按钮提交表单时,什么也没有发生。但是,如果我将模态移到foreach语句之外,则该窗体运行良好,但是只有最后一项的编辑按钮会弹出模态。其他人没有。如何修复我的代码?

0 个答案:

没有答案