[英]Laravel external URL issue
我想在一些錨標記中設置外部URL,但是當URL沒有http / https協議時會遇到問題。 當URL沒有這些協議時,URL如下所示:
<a target="_blank" href="www.usatoday.com/"></a>
當我單擊它或將鼠標懸停在它上面時,它顯示並將我重定向到: http://localhost/event/www.usatoday.com
我嘗試了以下兩種方法在href中工作,但沒有成功:
{{url($eventSponsorsRow->sponsorUrl)}}
{{ $eventSponsorsRow->sponsorUrl }}
而不是href中的URL。 Laravel 5.3
這是HTML和瀏覽器內容,而不是Laravel / PHP本身。
您只需要提供URL的協議部分以使其成為外部即可。
您可以跳過http:
但它至少需要在網址前面加雙斜杠,例如:
<a target="_blank" href="//www.usatoday.com/"></a>
請不要,如果您跳過http(s):
部分,它將使用當前使用的協議。
您需要在網址前面添加http://
make sure when you insert into a database it prepends http:// with it 如果您想使用確保當您插入數據庫時,它會以http://
<a target="_blank" href="{{ url($eventSponsorsRow->sponsorUrl) }}"></a>
如果您不想這樣做,則需要使用從數據庫獲取的url創建一個變量,並在http://前面加上
$newvariable = "http://$eventSponsorsRow->sponsorUrl";
並在正確的位置調用$ newvariable
<a target="_blank" href="{{ $newvariable }}"></a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.