[英]Laravel route not defined error
I keep getting route not defined error and if I use url()
I get server can not provide a secure connection error. 我不断收到未定义的路由错误,如果使用
url()
我无法获得服务器的安全连接错误。 I hope I can get some help. 希望我能有所帮助。
route 路线
Route::get('/show/{table_name}/{product_id}', 'PageCotroller@showdetails')->name('product-show');
View: 视图:
<h4><a href="{{ url('product-show' .$table_name . '/' .$product->item_id)}}">{{ $product->title }}</a></h4>
Controller: 控制器:
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'));
}
To call a route by name, you should use the route
function and add the parameters in an array as the second parameter. 要按名称调用路由,应使用
route
函数并将参数添加到数组中作为第二个参数。
route('product-show', [$table_name, $product->item_id])
The reason you get a route not defined error is that you are generating the url /product-show/{table_name}/{product_id}
and the actual url is /show/{table_name}/{product_id}
. 收到未定义路线的错误的原因是,您正在生成url
/product-show/{table_name}/{product_id}
,而实际的URL是/show/{table_name}/{product_id}
。 Also, adding the parameters manually is bad practice when there are many helper functions that do this for you. 另外,当有许多帮助程序功能可以手动执行时,手动添加参数也是一种不好的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.