laravel get base url

Posted by w3diy - 1 year ago

How to get Base URL in Laravel?

Laravel Get Base Url Syntax

$baseurl = url();
dump($baseurl);
Laravel: Get base url

normally use:

<a href="{{ url('/path/uri') }}">Edit Product</a>

Example 1: Accessing The Base URL

$url = url('');
$url = config('app.url'); 

Example 2. Accessing The Current URL

$url = url()->current();
$url = url()->full();
$url = url()->previous();

Example 3. URLs For Named Routes

$url = route('home');

Example 4. URLs To Assets(Public)

$url = asset('');

Example 5. File URLs

use Illuminate\Support\Facades\Storage;

$url = Storage::url('file.jpg');
$url = url($url);