请我需要你的帮助我正在使用 Laravel 6 将我的 html 代码从无序列表更改为表格后,我遇到了这个问题,我已经检查了视图代码,但没有看到错误
这是我的索引视图
<table class="table">
<thead class="simba-thead">
<tr>
<th>Codigo Interno / Codigo de Parte</th>
<th>Descripción</th>
<th>Percha / Bodega</th>
<th>Stock</th>
<th>Precio</th>
<th>Activo</th>
<th>Editar / Eliminar</th>
</tr>
</thead>
<tbody>
@forelse($products as $product)
<tr>
<td><a href="{{route('products.show',$product)}}">{{$product->internalCode}}</a><br>{{$product->partNumber}}</td>
<td>{{$product->description}}</td>
<td>{{$product->rack}}<br>{{$product->warehouse}}</td>
<td>1</td>
<td>{{$product->Price}}</td>
<td>{{$product->Active}}</td>
<td>edit/delete</td>
</tr>
@empty
<td>null</td>
<td>null</td>
<td>null</td>
<td>null</td>
<td>null</td>
<td>null</td>
<td>null</td>
</tr>
@endforelse
{{$products->links()}}
</tbody>
</table>
我的控制器
class ProductController extends Controller
{
public function index(){
return view('products.index',[
'products'=>Product::latest()->paginate()
]);
}
public function show(Product $product){
return view('products.show',[
'product'=>$product
]);
}
}
我的路线
Route::resource('products','ProductController')->names('products');
答案 0 :(得分:0)
问题是 Laravel 默认使用字段名称 'id' 来标识表中的主键。 我解决了将这一行添加到我的模型中的问题。
protected $primaryKey = 'productId';