Php Laravel在动态导航栏上显示产品页面链接

Php Laravel在动态导航栏上显示产品页面链接,php,laravel-5,routing,Php,Laravel 5,Routing,我目前刚接触laravel,我尝试创建一个包含3个类别的导航栏(衬衫和裤子分别为8号和9号)和10号 我通过两个表中的cat\u id列将产品表和类别表连接起来 我试图做到这一点,当用户单击类别下的产品链接时,它会将其留给具有自己的pro\u id的产品视图 这是我的控制器,带有主页的变量 public function index() { $pro_shirt=Products::where('cat_id','8')->get(); $pro_

我目前刚接触laravel,我尝试创建一个包含3个类别的导航栏(衬衫和裤子分别为8号和9号)和10号

我通过两个表中的
cat\u id
列将产品表和类别表连接起来

我试图做到这一点,当用户单击类别下的产品链接时,它会将其留给具有自己的
pro\u id
的产品视图

这是我的控制器,带有主页的变量

 public function index()
    {
        $pro_shirt=Products::where('cat_id','8')->get();
        $pro_pant=Products::where('cat_id','9')->get();
        $pro_dress=Products::where('cat_id','10')->get();
        return view('front.home',compact('pro_shirt','pro_pant','pro_dress'));
    }
这里是我的产品页面链接路线

Route::get('/product/{id}',['as' => 'front.product.show', 'uses' => 'HomeController@product']);
该产品页的控制器功能

   public function product($id){
        $product = Products::where('pro_id',$id)->Paginate(1);
        return view('front.product.product', compact('product'));
    }
这是我在刀片主视图中的导航栏

<div class="col1">
                                    <div class="h_nav">
                                        <a href="{{route('front.category.show', ['id' =>8]) }}"><h4>Shirt</h4></a>
                                        <ul>
                                        @foreach($pro_shirt as $shirt)
                                              <li><a href="{{route('front.product.show'),['id' =>$shirt->pro_id]}}">{{$shirt->pro_title}}</a></li>
                                        @endforeach
                                        </ul>
                                    </div>
                                </div>
                                <div class="col1">
                                    <div class="h_nav">
                                        <a href="{{route('front.category.show', ['id' =>9]) }}"><h4>Pant</h4></a>
                                        <ul>
                                        @foreach($pro_pant as $pant)
                                              <li><a href="{{route('front.product.show'),['id' =>$pant->pro_id]}}">{{$pant->pro_title}}</a></li>
                                        @endforeach
                                        </ul>
                                    </div>
                                </div>
                                <div class="col1">
                                    <div class="h_nav">
                                        <a href="{{route('front.category.show', ['id' =>10]) }}"><h4>Dress</h4></a>
                                        <ul>
                                        @foreach($pro_dress as $dress)
                                              <li><a href="{{route('front.product.show'),['id' =>$dress->pro_id]}}">{{$dress->pro_title}}</a></li>
                                        @endforeach
                                        </ul>
                                    </div>
                                </div>

    @foreach($pro_衬衫作为$shirt)
  • @endforeach
    @foreach($pro_pant作为$pant)
  • @endforeach
    @foreach($pro_dress as$dress)
  • @endforeach
当我尝试单击每个产品链接时,会显示一个错误:

缺少[Route:front.product.show][URI:product/{id}]所需的参数。(视图:C:\xampp\htdocs\webshop\resources\views\front\extends\master.blade.php)

我不知道为什么该产品的pro_id没有显示,但是pro_标题显示了


更新:我错过了路线中的一个关闭
,因此导航栏现在可以工作了

您的视图中有一个错误, 而不是
{route('front.product.show'),['id'=>$shirt->pro_id]}
需要
{{route('front.product.show',['id'=>$shirt->pro_id])}


对剩下的路线做同样的操作
front.product.show

天哪,它现在起作用了谢谢你:D,我想当我键入:D时我的眼睛累了。