2017-06-20 195 views
0

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

路线

Route::get('/show/{table_name}/{product_id}', '[email protected]')->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')); 

} 

回答

1

要调用由名字的路线,你应该使用route功能,并在数组中添加参数作为第二个参数。

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

你没有定义错误路线的原因是您正在生成的URL /product-show/{table_name}/{product_id}和实际的URL是/show/{table_name}/{product_id}。另外,手动添加参数是不好的做法,因为有很多帮助函数会为您执行此操作。

0

更改视图地址

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

OR

使用route帮手laravel