0

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);
Linas Lg
  • 199
  • 2
  • 17

4 Answers4

0

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.

Loek
  • 4,037
  • 19
  • 35
0

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

Ole K
  • 754
  • 1
  • 9
  • 32
  • Thank you, but i get such error: "InvalidArgumentException in UrlGenerator.php line 314: Route [search-user] not defined." P.S i also included routes file info in primary topic. – Linas Lg Jan 19 '17 at 11:47
0

If you have the route for it then you can do something like this,

return \Redirect::route('search-user/example@email.com');
  • Thank you, but i get such error: "InvalidArgumentException in UrlGenerator.php line 314: Route [search-user] not defined." Also i have tryed this one: return \Redirect::route('tnt6week-list.search-user')->with('email', $request->email); But same error. – Linas Lg Jan 19 '17 at 11:41
  • Yes, that's why I asked you whether you have a route for it or not? So how do you go to that view then? – LearningNew Jan 19 '17 at 11:42
  • Looking at your routes I can see that you have passed {email} in the route. so your redirect will look something like this, Redirect::route('search-user/asd@asd.com'); or similar. I also edited my answer – LearningNew Jan 19 '17 at 11:47
  • Thank you, but still having problems. My code: `return \Redirect::route('tnt6week-list.search-user/'.$request->email);` And i still get error: `InvalidArgumentException in UrlGenerator.php line 314: Route [tnt6week-list.search-user/email@domain.net] not defined.` – Linas Lg Jan 19 '17 at 12:06
  • With all due respect, but RTFM. https://laravel.com/docs/5.3/routing#named-routes ==> `Route::get( ... )->name('search-user');` – Loek Jan 19 '17 at 12:15
  • I would'nt post a question here, if i know how to achieve. Non of the answers are working. Maybe issue is somewhere else. I have read enough before posting this question. – Linas Lg Jan 19 '17 at 12:50
0

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.

VenomRush
  • 1,622
  • 3
  • 15
  • 25