Hello Artisan
In this turorial i will show you how we can generate URL in laravel without query string. Do you know how we can do it? Laravel provides several helpers to assist you in generating URLs for your application. These are mainly helpful when building links in your templates and API responses, or when generating redirect responses to another part of your application.
You can easily generate URL using laravel helper function. You can also use URL facades class to geberate URL in laravel. 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
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();
Hope it can help you.
#laravel #laravel-8x #url