缺少[Route:developer.variants.store] [URI:developer / {store} / products / {products} / variants]所需的参数

时间:2018-08-28 10:22:46

标签: php laravel-5

我的开发人员组中的web.php中有这条路线

    Route::get('{store}/products/{products}/variants', [
    'as' => 'variants.create',
    'uses' => 'VariantsController@create',
]);

Route::post('{store}/products/{products}/variants', [
    'as' => 'variants.store',
    'uses' => 'VariantsController@store',
]);

,其中{store}是一个标签,而{products}是uuid。

现在我的VariantsController @ create:

    public function create($store, $id)
{
    $store = Store::where('slug', $store)->firstOrFail();
    $product = $store->products()->findOrFail($id);
    return view('devoptions.products.variants', compact('store'));
}

和我的variants.blade.php

<div class="container">
    <div class="row">
            {!! Form::open([ 'route' => ['developer.variants.store', $store->slug], 
            'method' => 'POST' ]) !!}
       <div class="col-sm-12">
           <div class="page-header">
                //more code here

我得到了错误:

  

缺少[Route:developer.variants.store] [URI:developer / {store} / products / {products} / variant]所需的参数。 (查看:/Users/Kit/nowna-core-php-api/resources/views/devoptions/products/variants.blade.php)

我曾尝试传递$ product,但是我不知道怎么做,即使我尝试这样做也不起作用。请帮忙。

编辑:我尝试传递另一个参数:

                {!! Form::open([ 'route' => ['developer.variants.store', $store->slug, $product->uuid], 
            'method' => 'POST' ]) !!}

但是现在它给了我另一个错误:

  

未定义变量:存储(视图:/Users/Sample/project/resources/views/devoptions/products/variants.blade.php)

2 个答案:

答案 0 :(得分:1)

第二个参数和$ product-> uuid中缺少[],请尝试以下操作:

{!! Form::open([ 'route' => ['developer.variants.store', [$store->slug, $product->uuid]], 
        'method' => 'POST' ]) !!}

答案 1 :(得分:0)

尝试一下:

{!! Form::open([ 'route' => ['developer.variants.store', $store->slug, $product->uuid], 
            'method' => 'POST' ]) !!}