user8189215 user8189215 - 11 months ago 53
PHP Question

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 get helped!


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();
$query = DB::table($table_name)
->where('item_id', '=', $pid)
$pro_img = DB::table('item_images')
->where('prod_id', $pid)
return view('show_details',compact('categories','image','pro_img','table_name','shop_name'));


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download