Laravel: Get base url

set base url in laravel
laravel get base url without public
redirect to base url laravel
laravel get current url
laravel base url in js
laravel request url
laravel get base path
laravel url localhost

Simple question, but the answer seems quite hard to come by. In Codeigniter, I could load the url helper and then simply do

echo base_url();

to get my site's URL. Is there an equivalent in Laravel?

You can use the URL facade which lets you do calls to the URL generator

So you can do:


You can also use the application container:


Or inject the UrlGenerator:

namespace Vendor\Your\Class\Namespace;

use Illuminate\Routing\UrlGenerator;

class Classname
    protected $url;

    public function __construct(UrlGenerator $url)
        $this->url = $url;

    public function methodName()

URL Generation - Laravel, Why did it on get the base url or the domain name and not the correct I found this discussion:  Thankfully, Laravel makes it super easy to get base URL as well as build URLs from base. In order to get the base URL in Laravel, use the URL facade: URL::to('/'); This will output the link to

Laravel < 5.2

echo url();

Laravel >= 5.2

echo url('/');

Hope this helps you

url() only returns the base url, So as we know we may need to get base url of our website then we can get it several way in laravel 5 application. Here, i will give you several  Get the exact method by using Laravel Get Base Url with example & syntax. Online Assembly of web developing tutorials online at now!

For Laravel 5 I normally use:

<a href="{{ url('/path/uri') }}">Link Text</a>

I'm of the understanding that using the url() function is calling the same Facade as URL::to()

Laravel 7.x and 6.x Get Site URL Examples, laravel 5 get site url, laravel 5 get base url, laravel 5 url helper, laravel 5 base url, laravel get url path, laravel website path,laravel get  Get the base URL of your Laravel 5 app page available anywhere in your JavaScript for jQuery to use. To do this you could have the following code in your template.blade.php file

To get it to work with non-pretty URLs I had to do:


How to Get Site URL in Laravel?, you may use the url or fullurl methods to get base url in the controller. the url method will return the url without the query string, while the fullurl  Here is quick post, which can help you to get base url or home page url of your laravel application. I think many times we need to get site URL for something share or link, so you can get that using url helper and URL facade. Both way are same you can use that anywhere i mean in controller or view. so let's see.

Updates from 2018 Laravel release(5.7) documentation with some more url() functions and it's usage.

Question: To get the site's URL in Laravel?

This is kind of a general question, so we can split it.

1. Accessing The Base URL

// Get the base URL.
echo url('');

// Get the app URL from configuration which we set in .env file.
echo config('app.url'); 

2. Accessing The Current URL

// Get the current URL without the query string.
echo url()->current();

// Get the current URL including the query string.
echo url()->full();

// Get the full URL for the previous request.
echo url()->previous();

3. URLs For Named Routes

echo route('home');

4. URLs To Assets(Public)

// Get the URL to the assets, mostly the base url itself.
echo asset('');

5. File URLs

use Illuminate\Support\Facades\Storage;

$url = Storage::url('file.jpg'); // stored in /storage/app/public
echo url($url);

Each of these methods may also be accessed via the URL facade:

use Illuminate\Support\Facades\URL;

echo URL::to(''); // Base URL
echo URL::current(); // Current URL

How to call these Helper functions from blade Template(Views) with usage.

{{ url('/login') }}

{{ asset('css/app.css') }}

{{ route('login') }}

// usage

<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">

<!-- Login link -->
<a class="nav-link" href="{{ route('login') }}">Login</a>

<!-- Login Post URL -->
<form method="POST" action="{{ url('/login') }}">

Laravel Get Base URL in Controller, Get the base URL of your Laravel 5 app page available anywhere in your JavaScript for jQuery to use. To do this you could have the following code in your​  Laravel provides several helpers to assist you in generating URLs for your application. These are mainly helpful when building links in your templates and API responses, or when generating redirect responses to another part of your application. The Basics. Generating Basic URLs. The url helper may be used to generate arbitrary URLs for your application. The generated URL will automatically use the scheme (HTTP or HTTPS) and host from the current request:

Get base URL of Laravel 5 page using jQuery, PHP Laravel Get base url Examples,laravel 6,5,5.2,site,get,url,website,base,​helper,homepage,example,path,site,how,laravel 6 get homepage url. You can use this code to get current URL: echo url()->current(); echo url()->full(); I get this from Laravel documents.

PHP Laravel Get base url Examples • InfinityKnow, Hear we will give you detail about Laravel Get Absolute Path Document Root Base URL | twitteinfoAnd how to use it also give you demo for it if it is necessary. Helpers. Introduction; Available Methods; Introduction. Laravel includes a variety of global "helper" PHP functions. Many of these functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient. Available Methods Arrays & Objects

Laravel Get Absolute Path Document Root Base URL, Let's explore quick ways to get the site's base URL in Laravel. I had someone ask me how to do it in Laravel, because other frameworks like  Hi Guys, in the blog , i will explain to you how to create laravel get base url in the controller, we will create get base url in the controller. i will show a step by step simple get base url in laravel 7/6.

  • And despite its possible appearance from the example, this is relative to the Laravel's root path, so if you're installed in /something/ it'll make the right URL.
  • @deFreitas and #ceejayoz how to use URL::to with laravel localization?
  • @MubasharIqbal If I understood your question, {{URL::to('/my-page.html')}} at view and echo URL::to('/my-page.html'); at the code
  • nice handler, in my case: <a class="button is-primary" href="<?= URL::to('/'); ?>/atencion/reporte" target="_blank">, thanks!
  • Could you expand this answer to include an explanation instead of just a code-snippet?
  • Exam: I have site in local: localhost/abc In Codeigniter: echo base_url(); => I get localhost/abc In Laravel: echo url(); => I get localhost/abc too.
  • Use this for an url with segmentation: url().'/'.\Request::segment(1).'/'.\Request::segment(2)
  • Note that this no longer works in 5.2: You can use url('/') instead however
  • asset('/') seems better to me because it has trailing slash which is necessary in base href.
  • Note: if your website is served over https you can use the secure_url() function the same way, and this will produce an https link. Using url() on an https site will still produce an http link.
  • This one worked for me. Also useful to know the secure_url() syntax as well. Thanks.
  • I'm using Lumen 5.4. There url() generates a http or https link based on the protocol of the request. On the other hand secure_url() doesn't exist. Did this change in Laravel 5.4 too?
  • No, it's part of Larvel 5.4. I can't really comment because I have never used Lumen but the 5.4 Laravel documentation for secure_url() is available here:
  • To my need this is the best <base href="{{ asset('/') }}" />