model-view-controller - 路线 [$products.edit] 未定义
问题描述
@foreach($products as $product)
<tr>
<td>{{ $product->id }}</td>
<td>{{ $product->name }}</td>
<td>{{ $product->job_category }}</td>
<td>{{ $product->purpose }}</td>
<td>{{ $product->region }}</td>
<td>{{ $product->email }}</td>
<td>{{ $product->contact }}</td>
<td><a href="{{ route('$products.edit', $product->id) }}" class="btn btn-primary">Edit</a></td>
<td>
<form action="{{ route('$products.destroy', $product->id) }}" method="post">
@csrf
@method('DELETE')
<button class="btn btn-danger" type="submit">DELETE</button>
</form>
</td>
</tr>
@endforeach
这是我的产品控制器
$product = Product::findOrFail($id);
return view('products.edit', compact('product'));
这是我的路线
Route::resource('products', 'ProductController');
解决方案
只需$
从此处的路线名称中删除
href="{{ route('$products.edit', $product->id) }}"
//and here :
action="{{ route('$products.destroy', $product->id) }}"
应该
href="{{ route('products.edit', $product->id) }}"
action="{{ route('products.destroy', $product->id) }}"
推荐阅读
- r - 如何为ggplot强制geom_smooth渲染?
- c - “step”不是在程序结束时结束程序,而是在5个“step”之后结束它
- php - 从 laravel 中的对象中删除一个数组
- rust - 我如何从表达式中“返回”?
- swift - 如何从 API 获取信息?斯威夫特 4
- css - webkit-scrollbar 在 chrome 中不起作用
- wordpress - 显示特定类别的自定义 single.twig
- angular - angular4,typescript,MVC5 - 获取 404 错误到 html 模板文件
- laravel - 在 Lumen 包中使用用户模型
- android-studio - 如何反转 Gridview 布局以确保最新帖子位于顶部?