-1
@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');
4

1 回答 1

1

只需$从此处的路线名称中删除

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) }}"

于 2021-07-23T17:19:32.923 回答