[英]Laravel get redirect URL
我在獲取Laravel URL時遇到問題。
我有一個頁面,如果用戶未登錄,則會將用戶重定向到錯誤的url,並且顯示錯誤。
我正在使用redirect()->intended($this->redirectPath());
為了讓用戶在登錄后回到頁面上的位置,所以我不得不以某種方式編寫代碼來檢查什么是重定向URL,以及是否是會產生錯誤的URL,
我知道什么是URL,它必須將用戶重定向到我需要設置的另一個URL。
我嘗試了采用$this->redirectPath() == 'here goes the url'
就像redirect()->intended($this->redirectPath()) == 'again url here'
但是沒有任何效果。
嘗試這個:
return Redirect::intended('here goes the url');
要么
return Redirect::intended();
purposes intended()
檢查會話索引url.intended是否存在並默認重定向到它,否則重定向到$ default ='/',它可以被覆蓋。
您必須了解redirect()->intended()
實際作用。
它會尋找一個名為url.intended
的會話變量,就像session()->pull('url.intended')
(請注意, pull()
將在此調用后刪除該變量,這很方便,因為您通常只需要一次使用此變量) 。
當前僅在調用redirect()->guest('/yourpath')
時設置此變量(它將您的當前URL設置為url.intended
),除非您使用session()->put('url.intended')
以自己的邏輯手動設置它session()->put('url.intended')
。
因此,最明顯的使用方法是使用redirect()->guest('/login')
,然后在用戶成功登錄后,您可以使用redirect()->intended()
(無參數)進行重定向用戶返回到最初將他發送到登錄頁面的頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.