路由在控制器内部不起作用

Route is not working inside the controller

我使用 ajax 在 Laravel 中实现了自动完成搜索功能。我试图通过 href 内的路线,但它正在工作。我不知道如何在控制器中传递路线。请帮助我并给出解决方法。

$output = '';

        if (count($pro)>0)
        {
            foreach ($pro as $row)
            {
                $url = "{{ route('ProductDetail','.$row->prod_seo_title.') }}";

                $output .= '<li><a href="'.$url.'">'.$row->product_name.'</a></li>';
            }
        }
        else {

            $output .= '<li>'.'No results'.'</li>';
        }

        return $output;

现在我一点击li标签URL就变成这样了

https://testing.com/product-detail/%7B%7B%20route('ProductDetail','.Chiaro-Tote-1.')%20%7D%7D

我附上了截图

你在一个普通的 PHP 文件中,这不是 Blade。

$url = route('ProductDetail', $row->prod_seo_title);

直接在 href 中给出

$output .= '<li><a href="'.route('ProductDetail', $row->prod_seo_title).'">'.$row->product_name.'</a></li>';