Home Laravel Laravel Get Base URL in Controller

Laravel Get Base URL in Controller

by Shahriar Sagor

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

close

You may also like