簡體   English   中英

Laravel路由未定義錯誤

[英]Laravel route not defined error

我不斷收到未定義的路由錯誤,如果使用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'));

}

要按名稱調用路由,應使用route函數並將參數添加到數組中作為第二個參數。

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

收到未定義路線的錯誤的原因是,您正在生成url /product-show/{table_name}/{product_id} ,而實際的URL是/show/{table_name}/{product_id} 另外,當有許多幫助程序功能可以手動執行時,手動添加參數也是一種不好的做法。

變更檢視地址

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

要么

使用路線助手laravel

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM