Php 我的控制器认为我的店铺id是产品id

Php 我的控制器认为我的店铺id是产品id,php,laravel,laravel-5,laravel-routing,Php,Laravel,Laravel 5,Laravel Routing,我的控制员看不出“样品”是商店而不是产品。 我在我的web.php上有这条路线 Route::get('{store}/products/{products}/edit', [ 'as' => 'store.products.edit', 'uses' => 'ProductsController@edit', function($store) { $store = App\Models\Store::where('slug',

我的控制员看不出“样品”是商店而不是产品。 我在我的web.php上有这条路线

    Route::get('{store}/products/{products}/edit', [
    'as'    => 'store.products.edit',
    'uses'  => 'ProductsController@edit',
    function($store) {
        $store = App\Models\Store::where('slug', $store)->firstOrFail();
    }
]);
这是我的ProductsController@edit

    public function edit($id)
{
    $product = Product::findOrFail($id);

    return view('view here', compact('product'));
}
当我运行url时:

其中样本为{store},022fe902-7f4d-4db1-b562-04a7eb9f5a68为{product}

我得到这个错误:

没有模型[App\Models\Product]示例的查询结果

在我的问题中:

产品
中选择*


如果您有2个参数,则控制器中应按有效顺序包含这两个参数,因此您应具有:

public function edit($store, $id)
{
    $product = Product::findOrFail($id);

    return view('view here', compact('product'));
}
此外,您可能不需要:

function($store) {
   $store = App\Models\Store::where('slug', $store)->firstOrFail();
}
对于任何事情,但可能在控制器中,您应该执行以下操作:

$store = App\Models\Store::where('slug', $store)->firstOrFail();
$product = $store->products()->findOrFail($id);

假设您在此商店中有产品,并且希望确保不会有人编辑分配给其他商店的产品。

谢谢!正是我需要的