Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nic_ttr's avatar

How to get url from database ?

Hello! I'm a beginner and I'm trying to create my first website with Laravel. For each distributors, I stored an url (e.g in the table distributors I have the 'name'='CatenaPharmacy' and the url='www.catena.ro' . ) How can I get the ulr of distributors without my domain ? (I don't want http://mysite/catena , I want just www.catena.ro ).

0 likes
4 replies
nic_ttr's avatar

@bestmomo

In my view, I have : "

Name of pharmacy URL @foreach($distribuitors as $distribuitor) {{ $distribuitor->name}} {{$route->url}} @endforeach "

And in my controller : class AboutController extends Controller { public function distribuitorAbout() { $distribuitors = Distribuitor::all(); URL::route($route, [], false); return view('about', ['distribuitors' => $distribuitors]); }

}

How can I use parse_ url to be able to acces every url of the distributors when I click on the link displayed in the table above? P.s : sorry if it's a stupid question... Please, help me.

Snapey's avatar
Snapey
Best Answer
Level 122

You need to decide if you will store http:// or https:// with the domain name.

If you just put the domain name on the page;

<a href="{{ $distributor->url }}">{{ $distributor->name }}</a>

then the URL will be relative to your website, so the URL needs to start with http: or https:

You could do this like;

<a href="http://{{ $distributor->url }}">{{ $distributor->name }}</a>

but there are two problems with this.

  1. Your url might need to be https not http

  2. You might copy the URL straight into your database and it may already start http:// - now you have added it twice.

Best option is to ensure when the URL is added to the database it includes the http or https in the first place.

nic_ttr's avatar

@Snapey Many thanks, sir! In my database, I stored initally the adresses without http and/or https but as soon as I updated the table, the problem has been solved. Have a nice day!

Please or to participate in this conversation.