路线[产品/产品]未定义。 (视图:

时间:2019-08-16 07:04:21

标签: laravel eloquent laravel-5.8

他试图从索引页面获取与该类别相关的产品,但是它显示错误,所有这些事情在管理员方面都可以正常工作,而在用户方面却没有问题,

index.blade.php:

     @foreach($categories as $category)
            <div class="col-sm-10 col-md-8 col-lg-4 m-l-r-auto">
                <!-- block1 -->

                <div class="block1 hov-img-zoom pos-relative m-b-30">
                    <img src="{{ URL::to('/') }}/images/backend_images/category_images/{{ $category->category_image }}" class="img-thumbnail" style="width: 370px; height: 448px;" />

                    <div class="block1-wrapbtn w-size2">
                        <!-- Button -->
                        <a href="{{ route('product/products', $category->id) }}" class="flex-c-m size2 m-text2 bg3 hov1 trans-0-4">
                            {{ ucwords($category->category_name) }}
                        </a>
                    </div>
                </div>
            </div>
            @endforeach

路线:

  Route::get('/product/{id}','ProductController@products');

route:list

paste.ofcode.org/Yw3CU2MXdCQXpxh9H3vKYh

2 个答案:

答案 0 :(得分:0)

更改此:

<a href="{{ route('product/products', $category->id) }}" class="flex-c-m size2 m-text2 bg3 hov1 trans-0-4">
  {{ ucwords($category->category_name) }}
</a>

对此:

<a href="{{ route('admin.product.show', $category->id) }}" class="flex-c-m size2 m-text2 bg3 hov1 trans-0-4">
  {{ ucwords($category->category_name) }}
</a>

答案 1 :(得分:0)

一种更好的方法是使用这样的名称来定义您的路线:

Route ::get('/product/{id}','ProductController@products')->name('product.products');

然后像这样指定您的链接:

<a href="{{ route('product.products', $category->id) }}" class="flex-c-m size2 m-text2 bg3 hov1 trans-0-4">
    {{ ucwords($category->category_name) }}
</a>