Friday, 7 May 2021

Laravel URL class


https://laravel.com/docs/5.7/urls


 url() is global helper in laravel > 5.7

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:

$post = App\Post::find(1);

echo url("/posts/{$post->id}");

// http://example.com/posts/1

Accessing The Current URL

If no path is provided to the url helper, a Illuminate\Routing\UrlGenerator instance is returned, allowing you to access information about 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();

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

use Illuminate\Support\Facades\URL;

echo URL::current();

No comments:

Post a Comment