Laravel route not defined error(Laravel 路由未定义错误)
问题描述
我不断收到未定义路由的错误,如果我使用 url()
我得到服务器无法提供安全连接错误.我希望我能得到一些帮助.
I keep getting route not defined error and if I use url()
I get server can not provide a secure connection error.
I hope I can get some help.
路线
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
函数并将参数添加到数组中作为第二个参数.
To call a route by name, you should use the route
function and add the parameters in an array as the second parameter.
route('product-show', [$table_name, $product->item_id])
您收到路由未定义错误的原因是您正在生成 url /product-show/{table_name}/{product_id}
而实际 url 是 /show/{table_name}/{product_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}
. Also, adding the parameters manually is bad practice when there are many helper functions that do this for you.
这篇关于Laravel 路由未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 路由未定义错误


基础教程推荐
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的foreach复选框POST 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的PDF导出 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01