繁体   English   中英

如何向控制器发送多个 id

[英]How do I send multiple id to controller

我想将我的 id 发送到控制器,但我的 id 被逗号分隔,如212,233,121 ,它来自 JavaScript。 如何根据基于 JavaScript 的数字逗号拆分中的值发送我的 id?

url 应该像这样http://localhost/fics/public/reporting/reporting/getcust/212/233/121 ,这是后面的数字,基于我用逗号分隔的值。

这是我的代码:

for (var h = 0; h < storeItem.length; h++)
{
    if (l == storeItem[h]) {
        popVal = popVal + tempItem[i][l];
        //popval value from my other window .Example " 002,212,212"
    }
}

我的查看路线按钮 onclick:

onclick="openNewWindow('{{ route('reporting.getcust') }}')"

我的 web.php:

Route::group(['prefix' => 'reporting'], function () {
    Route::get('reporting/getcust/{id}','GenReportController@getcust')->name('reporting.getcust');
});

控制器:

public function getcust(Request $request){  
    $id = $_GET['id'];
}

如果 JavaScript 生成像http://localhost/fics/public/reporting/reporting/getcust/002,212,212 这样的 URL 然后你可以使用explode方法获取控制器中的所有ID

public function getcust(Request $request)
{ 
    $ids = explode(",", $request->id);

    foreach ($ids as $id) 
    {
        echo $id;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM