I have such URL in Laravel 5:
domain.com/search-user/email@domain.net
When I enter this URL, it automatically searches data by given email.
How I should redirect user from other controller to this URL?
I have tried, but it doesn't work:
return view(‘controller.search-user')->with('email', $request->email);
My routes file:
Route::post('/search-user', 'tnt6weeklistController@postSearchUser');
Route::get('/search-user/{email}', 'tnt6weeklistController@postSearchUser');
-------SOLVED---------- Solved issue only with this code (maybe it is not the best practice, but other solutions didn't worked):
return \Redirect::to('http://domain.com/search-user/'.$request->email);
I guess this would work.
return url('/search-user/' . urlencode($request->email));
Note that this changes @
into %40
(see here), so you need to replace that in the place you handle this request.
alternatively to what Loek answered you can set the arguments of the route using redirect()->route()
method
Example:
return redirect()->route('search-user', ['email' => $request->email]);
Assuming that "email" is a proper route parameter.
More Details: https://laravel.com/docs/5.3/redirects
If you have the route for it then you can do something like this,
return \Redirect::route('search-user/example@email.com');
I would suggest using $_GET for this, so instead of having the url as you have it, do this instead:
domain.com/search-user/?email=email@domain.net
And change your code so that you're processing $_GET['email']
. This should help with the redirect problem.