How to get base url in laravel using php?

Today, We want to share with you laravel base url.In this post we will show you get base path in laravel, hear for get base url or home page url of your laravel application we will give you demo and example for implement.In this post, we will learn about get base path in laravel with an example.

Laravel Get Base URL in Controller

How to Get Site URL in Laravel?

$url = URL::to("/");
print_r($url);


$url2 = url('/');
print_r($url2);

Example 1:
Here url method to getBaseURL in controller


public function getBaseURL()
{
    $url  = url()->full();
    print_r($url);
}

Example 2:
Now in this example in request facade of url method using getBaseURL in laravel controller


public function getBaseURL()
{
    $url  = \Request::url();
    print_r($url);
}

Example 3:
Here in this example in request facade of fullUrl method using getBaseURL in laravel controller


public function getBaseURL()
{
    $url  = \Request::fullUrl();
    print_r($url);
}

Example 4:
Now In this example in url facade of current method using getBaseURL in laravel controller


public function getBaseURL()
{
    $url  = \URL::current();
    print_r($url);
}

I hope you get an idea about laravel url helper.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment