如何在 Laravel 4.2 中使用查询字符串重定向命名路由 [英] How to redirect a named route with querystring in Laravel 4.2
问题描述
我是 Laravel 框架的新手.我正在使用 4.2 我的问题是我有一个分页功能在manageemployee 页面中,我为manageemployee 页面创建了一个路由.
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.
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.
现在页面看起来像 /usercp/manageemployee?page=3 删除该页面中的特定记录后,我需要将用户重定向到同一页面.
now the page looks like /usercp/manageemployee?page=3 After deleting a particular record in that page i need to redirect user to the same page.
我的重定向代码如下
return Redirect::route('getManageCompanyEmployee')->with('success','Record deleted successfully');
但是使用上面的代码,用户会像/usercp/manageemployee 这样进入第一页.但是重定向后用户需要在第三页/usercp/manageemployee?page=3.
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.
如何做到这一点?
推荐答案
你传递给路由的所有不是路由参数的东西,都会自动变成路由查询:
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');
但你也可以这样做:
return Redirect::refresh()->with('success','Record deleted successfully');
让用户保持在同一页面.
Keeping the user in the very same page.
或
return Redirect::back()->with('success','Record deleted successfully');
取决于您的用例.
这篇关于如何在 Laravel 4.2 中使用查询字符串重定向命名路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!