缺少[路由:brands.destroy] [URI:brands / {brand}]所需的参数。
@foreach ($brands as $key => $brand)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $brand->name }}</td>
<td>{{ $brand->detail }}</td>
<td>
<form action="{{ route('brands.destroy',$brand->id) }}" method="POST">
<a class="btn btn-info" href="{{ route('brands.show',$brand->id) }}">Show</a>
@can('product-edit')
<a class="btn btn-primary" href="{{ route('brands.edit',$brand->id) }}">Edit</a>
@endcan
@csrf
@method('DELETE')
@can('product-delete')
<button type="submit" class="btn btn-danger">Delete</button>
@endcan
</form>
</td>
</tr>
@endforeach
public function destroy(Brand $brand)
{
$brand->delete();
return redirect()->route('brands.index')
->with('success', 'Brand deleted successfully');
}
+--------+-----------+---------------------------------+----------------------+------------------------------------------------------------------------+-------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+---------------------------------+----------------------+------------------------------------------------------------------------+-------------------+
| | GET|HEAD | brands | brands.index | App\Http\Controllers\BrandController@index | web,auth |
| | POST | brands | brands.store | App\Http\Controllers\BrandController@store | web,auth |
| | GET|HEAD | brands/create | brands.create | App\Http\Controllers\BrandController@create | web,auth |
| | DELETE | brands/{brand} | brands.destroy | App\Http\Controllers\BrandController@destroy | web,auth |
| | PUT|PATCH | brands/{brand} | brands.update | App\Http\Controllers\BrandController@update | web,auth |
| | GET|HEAD | brands/{brand} | brands.show | App\Http\Controllers\BrandController@show | web,auth |
| | GET|HEAD | brands/{brand}/edit | brands.edit | App\Http\Controllers\BrandController@edit | web,auth |
+--------+-----------+---------------------------------+----------------------+------------------------------------------------------------------------+-------------------+
答案 0 :(得分:0)
为什么您以一种形式包含许多路线?
<form action="{{ route('brands.destroy',$brand->id) }}" method="POST">
<a class="btn btn-info" href="{{ route('brands.show',$brand->id) }}">Show</a>
@can('product-edit')
<a class="btn btn-primary" href="{{ route('brands.edit',$brand->id) }}">Edit</a>
@endcan
@csrf
@method('DELETE')
@can('product-delete')
<button type="submit" class="btn btn-danger">Delete</button>
@endcan
</form>
答案 1 :(得分:0)
这可能是因为您需要像这样定义参数。
<form action="{{ route('brands.destroy', ['brand' => $brand->id]) }}" method="POST">
您不必总是这样做,但是我遇到了我不得不这样做的问题。
如果不是这种情况,我会不知所措,因为这一切对我来说都很不错。
答案 2 :(得分:0)
您应该检查$brand->id
是否为null
。
如果可能的话,将参数作为关联数组传递给route
帮助器是明智的,至少是一个数组,但对于一个参数,它将采用单个值。如果您传递一个null
值,就好像您根本没有传递参数一样。
答案 3 :(得分:0)
在以下位置更改视图中的一些代码:
<form action="{{ route('brands.destroy', $brand->id) }}" method="POST">
...
...
</form>
收件人:
<form action="{{ route('brands.destroy', [$brand->id_brand]) }}" method="POST">
...
...
</form>