如何在 Laravel 4.2 中使用查询字符串重定向命名路由

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25765874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:04:50  来源:igfitidea点击:

How to redirect a named route with querystring in Laravel 4.2

laravelroutingquery-string

提问by user3408779

I am new to Laravel framework. I am using 4.2 my question is i had a pagination functionality in a manageemployee page, I have created a route for manageemployee page.

我是 Laravel 框架的新手。我正在使用 4.2 我的问题是我在管理人员页面中有一个分页功能,我为管理人员页面创建了一个路由。

Route::get('/usercp/manageemployee',array('uses' =>'ManageEmployeeController@getManageCompanyEmployee','as' =>'getManageCompanyEmployee'));

In this page i have pagination , if user was in third page, he want to delete one record.

在这个页面我有分页,如果用户在第三页,他想删除一条记录。

now the page looks like /usercp/manageemployee?page=3After deleting a particular record in that page i need to redirect user to the same page.

现在页面看起来像/usercp/manageemployee?page=3删除该页面中的特定记录后,我需要将用户重定向到同一页面。

My Redirect code as follows

我的重定向代码如下

return Redirect::route('getManageCompanyEmployee')->with('success','Record deleted successfully');

But with the above code user comes to the first page like /usercp/manageemployee. But after redirecting user needs to be in 3rd page /usercp/manageemployee?page=3.

但是使用上面的代码,用户会像 /usercp/manageemployee 这样进入第一页。但是重定向后用户需要在第三页/usercp/manageemployee?page=3。

How to acheive this?

如何实现这一目标?

回答by Antonio Carlos Ribeiro

Everything you pass to your route that is not a route parameters, becomes a route query automatically:

您传递给路由的所有不是路由参数的内容都会自动成为路由查询:

return Redirect::route('getManageCompanyEmployee', ['page' => 3])
        ->with('success','Record deleted successfully');

But you could also do:

但你也可以这样做:

return Redirect::refresh()->with('success','Record deleted successfully');

Keeping the user in the very same page.

使用户保持在同一页面上。

Or

或者

return Redirect::back()->with('success','Record deleted successfully');

Depending on your use case.

取决于您的用例。