Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect a named route with querystring in Laravel 4.2

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.

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.

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.

How to acheive this?

like image 593
user3408779 Avatar asked Sep 10 '14 12:09

user3408779


1 Answers

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.

like image 181
Antonio Carlos Ribeiro Avatar answered Nov 08 '22 06:11

Antonio Carlos Ribeiro