的 POST 方法<form>在 laravel 5.6 中的刀片文件@foreach内不起作用



在@foreach中使用表单后按钮不起作用。关于如何在@foreach循环中使用表单的任何建议?

甚至可以在 Laravel 刀片文件中的循环内使用表单吗?

这是我的Laravel刀片文件的代码。我在foreach中使用了表单来获取账面金额的数据。关于如何解决这个问题的任何建议?

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Items On Cart:</h4>
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
<table style="border-collapse: collapse;width: 100%;">
<tr style="border: 1px solid #dddddd;text-align: left;padding: 8px;font-size:20px;color: gray">
<th>Book Name</th>
<th>Author Name</th>
<th>Book Amount</th>
<th>Price</th>
<th>Action</th>
<th>Action</th>
</tr>
@foreach($cart_items as $data)
<form action="{{ route('change_item_amount',[$cart_info->id,$data->book_id]) }}" method="POST">
<tr>
<th>{{ show_books_name($data->book_id) }}</th>
<th>{{ show_books_author($data->book_id)  }}</th>
<th><input type="number" name="amount" id="amount" value="{{ $data->item_amount }}"></th>
<th>{{ $data->price }} tk</th>
<th><button type="submit" class="btn btn-success">Change</button></th>
<th><a class="btn btn-success" href="{{ route('delete_book',[$cart_info->id,$data->book_id] ) }}">Delete</a></th>
</form>
@endforeach
</table>
</div>
<h2 style="padding-left:865px">Total = {{ $cart_info->total_price }} tk</h2>
</div>
</form>
</div>
</div>
</div>
@endsection

最简单的解决方案可以是:将表单标签放入td中,(顺便说一句,它应该是td,而不是th,你在thead中使用th(:

<table style="border-collapse: collapse;width: 100%;">
<tr style="border: 1px solid #dddddd;text-align: left;padding: 8px;font-size:20px;color: gray">
<th>Book Name</th>
<th>Author Name</th>
<th>Book Amount</th>
<th>Price</th>
<th>Action</th>
<th>Action</th>
</tr>
@foreach($cart_items as $data)
<tr>
<td>{{ show_books_name($data->book_id) }}</td>
<td>{{ show_books_author($data->book_id)  }}</td>
<td>&nbsp; <!-- Here we have empty td now --> </td>
<td>{{ $data->price }} tk</td>
<td>
<!-- Form is here now -->
<form action="{{ route('change_item_amount',[$cart_info->id,$data->book_id]) }}" method="POST">
<input type="number" name="amount" id="amount" value="{{ $data->item_amount }}">
<button type="submit" class="btn btn-success">Change</button>
</form>
</td>
<td><a class="btn btn-success" href="{{ route('delete_book',[$cart_info->id,$data->book_id] ) }}">Delete</a></td>
@endforeach
</table>

最新更新