後爲了解決這個問題,我在php中編寫了一個url解析器幫助函數來查找並替換URL中的某些內容。符號(查詢部分)
//for displayPerPage, orderBy and sortBy parse the url and replace with new values
function urlQueryParse($queryToReplace, $newValue){
// extract query from url
$fullUrl = Request::fullUrl();
if(strpos($fullUrl, '?') !== false){
//find everything after the ? in url
$url = substr($fullUrl, strpos($fullUrl, "?") + 1);
// check url to make sure $queryToReplace exists in the url
if(strpos($url, $queryToReplace) !== false) {
// look through the remaining url query and replace whats given to the function
$newUrL = preg_replace('/('. $queryToReplace. '\=)([^&]+)/', $queryToReplace.'='.$newValue, $url);
return Request::url()."?{$newUrL}";
}
// if the ? exists but the queryToReplace is not in the url, then add it to the query string
return Request::url()."?{$url}&{$queryToReplace}={$newValue}";
}
//if the url doesnt have ? sign then simply insert the new value
return Request::url()."?{$queryToReplace}={$newValue}";
}
希望這可以幫助某人。如果您有任何改進的方法,歡迎提出建議。
P.S.我正在研究Laravel 5.2
如果您嘗試分頁,那麼您可以使用這個$ users = DB :: table('users') - > simplePaginate(15); – EaBangalore
一個可以通過這個來查看 – EaBangalore