Laravel Get Base URL in Controller

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this blog , i will explain to you how can we create laravel base url in the controller. Now here i will show you how to create get base url in the controller. Here i will show it in step by step with simple get base url in laravel application.

We may use the url or fullurl methods to get the base url in your controller. We know that the url method will return the url without the query string, while the fullurl method will includes the query string by using the get base url in the controller. So you can get by using url facade methods to get base url in the controller.

So here is the examples following different types to get the base url in the controller

Example: 1

Here url method to get url in controller

/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
    $url  = url()->full();
    print_r($url);
}

Example: 2

Now in this example in request facade of url method using get url in controller

/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
    $url  = \Request::url();
    print_r($url);
}

Example: 3

Now Here in this example in request facade of fullUrl method using get url in controller

/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
    $url  = \Request::fullUrl();
    print_r($url);
}

Example: 4

So now In this example in url facade of current method using get url in controller

/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
    $url  = \URL::current();
    print_r($url);
}

Read Also : Laravel Pagination with Ajax Example

Thank you read.Hope it will help you. Also follow on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →