Nabid Anzum
Nabid Anzum

Reputation: 250

How to add external link from Database in laravel?

In my Laravel project I have created a input field where facebook account link will be given as input. This input will store in the database. Then I create an object of that table and used the link in tag. i was expecting that this will take me to the given facebook account link. But it is creating a route like this /link. How can I solve this.

This code is for input field

<div class="form-group col-md-12">
                          <label for="name" class=" form-control-label">
                             Facebook ID
                          <span class="reqfield">*</span>
                          </label>
                          <input type="text" id="fb_link" placeholder="Facebook ID" class="form-control" name="fb_link" required value="{{$data->fb_link}}">
                       </div>

And this code is for Showing the link:

</li><li><a href="{{$setting->fb_link}}"><span class="fa fa-play"></span>Facebook</a>

The file is Here

Upvotes: 1

Views: 883

Answers (2)

OMi Shah
OMi Shah

Reputation: 6186

It's because your URL is missing the PROTOCOL ( http, https, etc. )

You need to append a valid protocol with the URL before saving to the database or in your view.

Example, in your view:

</li><li><a href="http://{{$setting->fb_link}}"><span class="fa fa-play"></span>Facebook</a>

You can also use the Laravel's inbuild validation method to check if the entered URL by the user is valid or not. Check https://laravel.com/docs/7.x/validation#rule-url

Upvotes: 1

VIKAS KATARIYA
VIKAS KATARIYA

Reputation: 6005

Its the client browser that does this. Nothing to do with Laravel or blade

If a href does not start with a protocol then it is assumed to be local to the current site.

You need to check the link when it is given to you, and if it starts http:// ot https:// then leave it alone, otherwise add http:// to the url before you save it in the database.

Force the URL to lowercase before you check incase they gave HTTP:// or even hTTp://

Upvotes: 1

Related Questions