【问题标题】:Missing required parameters for [Route: developer.variants.store] [URI: developer/{store}/products/{products}/variants][Route: developer.variants.store] [URI: developer/{store}/products/{products}/variants] 缺少必需参数
【发布时间】:2018-08-28 10:22:46
【问题描述】:

我在 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} 是 slug,而 {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'));
}

还有我的 variant.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}/variants] 的必需参数。 (查看:/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)

【问题讨论】:

  • 运行php artisan view:clear,如果错误仍然存​​在,则发布整个variants.blade.php。

标签: php laravel-5


【解决方案1】:

在第二个参数和 $product->uuid 中缺少 [],试试这个:

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

【讨论】:

    【解决方案2】:

    试试这个:

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

    【讨论】:

    • 已经试过了,现在它说 Undefined variable: store (View: variables.blade.php)
    • 请编辑您的问题,发布 variant.blade.php 和新的错误消息。
    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-22
    • 2022-01-16
    • 2021-03-10
    • 2020-08-17
    相关资源
    最近更新 更多