【问题标题】:Laravel route not defined errorLaravel 路由未定义错误
【发布时间】:2017-11-23 04:44:22
【问题描述】:

我不断收到路由未定义错误,如果我使用url(),我会收到服务器无法提供安全连接错误。 我希望我能得到一些帮助。

路线

Route::get('/show/{table_name}/{product_id}', 'PageCotroller@showdetails')->name('product-show');

查看:

<h4><a href="{{ url('product-show' .$table_name . '/' .$product->item_id)}}">{{ $product->title }}</a></h4>

控制器:

   public function showdetails($table_name,$pid){

       $categories = Category::all();
       $data['product_id']=$pid;
       $data['table']=$table_name;
       $shop_name=Shop::all();
       $query = DB::table($table_name)
       ->select('*')
       ->where('item_id', '=', $pid)
       ->get();;
       $image=Item_image::all();
           $pro_img = DB::table('item_images')
               ->select('image_loc')
               ->where('prod_id', $pid)
               ->get();
   return view('show_details',compact('categories','image','pro_img','table_name','shop_name'));

}

【问题讨论】:

    标签: php laravel url laravel-5 routes


    【解决方案1】:

    要通过名称调用路由,您应该使用route 函数并将参数添加到数组中作为第二个参数。

    route('product-show', [$table_name, $product->item_id])
    

    您收到路由未定义错误的原因是您正在生成 url /product-show/{table_name}/{product_id},而实际的 url 是 /show/{table_name}/{product_id}。此外,当有许多帮助函数为您执行此操作时,手动添加参数是不好的做法。

    【讨论】:

      【解决方案2】:

      更改查看地址

      <h4><a href="{{ url('product-show/' .$table_name . '/' .$product->item_id)}}">{{ $product->title }}</a></h4>
      

      使用 route 助手 laravel

      【讨论】:

        猜你喜欢
        • 2018-06-27
        • 2019-01-15
        • 2021-05-01
        • 2016-01-30
        • 1970-01-01
        • 2017-05-02
        • 2020-05-22
        • 2017-05-15
        • 2018-06-30
        相关资源
        最近更新 更多