Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.4k views
in Technique[技术] by (71.8m points)

php - 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. 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'));

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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])

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...