从 JavaScript 发送 laravel ( app()->getLocale() ) 和 url

sent laravel ( app()->getLocale() ) with url from JavaScript

我在我工作的网站上添加了其他语言。

我制作奖章:

    class SetLocale {
         public function handle($request, Closure $next)
                {
                   App()->setLocale($request->segment(1));
                   return $next($request);
                }
              }

路线:

  Route::group(
  ['prefix' => '{locale}', 
  'where' => ['locale' => 'en|fr|ar'],
  'middleware' => 'setlocale'],function ()
        {
           Route::get('mapData','HomPageController@mapData')->name('mapData');
        });

一切正常,但是:我有一张来自 https://www.amcharts.com/ 的地图停止工作,因为我不知道如何通过

    app()->getLocale()

在JavaScript语言的地图鳕鱼旁边

      polygonSeries.dataSource.url = "mapData";  

那么我怎样才能把 dataSource.url 中的 $langLocale 变成这样

polygonSeries.dataSource.url = "mapData",  app()->getLocale();

我想出了办法让它工作,但这种方式是静态的而不是动态的,这就是我所做的:

       polygonSeries.dataSource.url = "/en/mapData";

那么有什么办法可以弄清楚这段代码 app()->getLocale(); 中的语言是什么,并将其作为参数形式发送 JavaScript 文件

这就是答案:将 JavaScript 的 cod 放入函数中,然后将 php 文件

中的值发送给它
  <script>
mapJs("  {{route('mapData',app()->getLocale())}}");
</script>

在 javascript 文件中开始这样的代码:

function mapJs(value) {
  polygonSeries.dataSource.url = value;
 }