On my website, users can share URLs.
These are stored as a text
type in my database.
These links are displayed like so:
<a href="{{ $submission->link }}" rel="nofollow">{{$submission->title}}</a>
The problem with this is that blade adds the domain in front of URL if an href is detected.
So if the link is www.google.com
it'll look like http://localhost/www.google.com
However if the link is https://www.google.com
it'll work fine.
A solution I saw when I searched this problem is to put //
at the start of the href, like so:
<a href="//{{ $submission->link }}" rel="nofollow">{{$submission->title}}</a>
This works fine for links that start with www.
, but if I do https://www.google.com the URL will look like this:
https//www.google.com
Notice the lack of :
What's the most elegant solution to this problem? Do I remove https before storing to the database? Do I make it so that if there's an https, I print the link as normal, but if there's no https I add //
?