2017-01-19 59 views
0

我在Laravel 5這樣的URL:如何將用戶重定向到自定義URL(視圖)?

domain.com/search-user/[email protected] 

當我進入這個URL,它會自動給出電子郵件搜索數據。

我應該如何將用戶從其他控制器重定向到此URL?

我都試過了,但它不工作:

return view(‘controller.search-user')->with('email', $request->email); 

我的路線文件:

Route::post('/search-user', '[email protected]'); 
Route::get('/search-user/{email}', '[email protected]'); 

-------解決--------- - 解決問題,只能用這個代碼(也許它不是最好的做法,但其他解決方案沒有工作):

return \Redirect::to('http://domain.com/search-user/'.$request->email); 

回答

0

我想這會工作。

return url('/search-user/' . urlencode($request->email)); 

注意這改變@%40see here),所以你需要更換,在你處理此請求的地方。

0

或者什麼Loek回答您可以使用redirect()->route()方法

舉例設置路由的參數:

return redirect()->route('search-user', ['email' => $request->email]); 

假設「電子郵件」是一個合適的路由參數。

更多詳細信息:https://laravel.com/docs/5.3/redirects

+0

謝謝,但我得到這樣的錯誤:「InvalidArgumentException在UrlGenerator.php行314:路由[搜索用戶]未定義。」我還在主題中包含了路線文件信息。 –

0

如果你有,那麼你可以做這樣的事情的路線,

return \Redirect::route('search-user/[email protected]'); 
+0

謝謝,但我得到這樣的錯誤:「InvalidArgumentException UrlGenerator.php行314:路由[搜索用戶]未定義。」我也試過這一個:return(\'Redirect :: route'''tnt6week-list.search-user') - >('email',$ request-> email);但同樣的錯誤。 –

+0

是的,這就是爲什麼我問你是否有路線嗎?那麼你怎麼去那個觀點呢? – LearningNew

+0

查看您的路線,我可以看到您已在路線中通過{email}。所以你的重定向將看起來像這樣,Redirect :: route('search-user/[email protected]');或類似的。我也編輯了我的答案 – LearningNew

0

我會建議使用$ _GET這個,所以不是具有URL作爲你擁有它,而是執行此操作:

domain.com/search-user/[email protected]

,改變你的代碼,以便您正在處理$_GET['email']。這應該有助於重定向問題。

相關問題