如果我在第二个"id"'=' 1 位于 where(( 部分的地方放一个数字,那么它适用于该行,但需要它对所有行都是自动的吗?
在控制器中,代码为:
public function update()
{
$editproducts = DB::table('products')->get();
$updates = DB::table('products')
->where('id', '=', 'id')
->update([
'plant' => request('plant'),
'description' => request('description'),
'price' => request('price'),
'stock' => request('stock'),
'created_at' => request('created_at')
]);
return view('adminstock', compact(['updates', 'editproducts']));
}
页面上的代码是:
<table class="table table-bordered">
<thead>
<tr>
<th>ID No</th>
<th>Plant</th>
<th>Description</th>
<th>Price</th>
<th>Stock</th>
<th>created on</th>
</tr>
</thead>
<tbody>
@foreach($editproducts as $pro)
<form method="post" action="editproducts">
{{csrf_field()}}
<tr>
<td><input class="bigger" type="text" name="id" value="{{$pro->id}}" readonly /> </td>
<td><input class="bigger" type="text" name="plant" value="{{$pro->plant}} "/> </td>
<td><input class="bigger" type="text" name="description" value="{{$pro->description}} "/></td>
<td><input class="bigger" type="text" name="price" value="{{$pro->price}} "/> </td>
<td><input class="bigger" type="text" name="stock" value="{{$pro->stock}} "/></td>
<td><input class="bigger" type="text" name="created_at" value="{{$pro->created_at}} "/></td>
<td><button type="submit" class="btn btn-danger" > Edit </button></td>
</tr>
</form>
@endforeach
</tbody>
</table>
我通过更改使其工作:
->where('id', '=', 'id')
对此:
->where('id', '=', $_POST['id'])