首页 > 解决方案 > 路线 [$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');

标签: model-view-controllerlaravel-7laravel-resource

解决方案


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

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


推荐阅读