Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel external URL issue

I want to set external URL in some of my anchor tags but facing problem when URL is without http/https protocol. When URL is without these protocols URL become like following:

<a target="_blank" href="www.usatoday.com/"></a>

when I click on it or hover over it, it shows and redirect me to: http://localhost/event/www.usatoday.com

I've tried following two ways in href but didn't worked:

{{url($eventSponsorsRow->sponsorUrl)}}
{{ $eventSponsorsRow->sponsorUrl }}

instead of URL in href. Laravel 5.3

like image 849
ÛmÄîr MÄlîk Avatar asked Dec 14 '16 12:12

ÛmÄîr MÄlîk


1 Answers

This is HTML and browser stuff, not Laravel/PHP itself.

You just need to provide protocol part of the url to make it external.

You can skip the http: but it needs at least double slash in front of the url like:

<a target="_blank" href="//www.usatoday.com/"></a>

Please not, that if you skip the http(s): part it will use currently used protocol.

like image 75
Jakub Matczak Avatar answered Oct 06 '22 00:10

Jakub Matczak