Hello,
Today, i we will show you laravel 8 generate dynamic URL. This article will give you simple example of laravel 8 generate dynamic URL. you will laravel 8 generate dynamic URL. In this article, we will implement a laravel 8 generate dynamic URL.
So let’s follow few step to create example of laravel 8 generate dynamic URL.
Example
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Product; class TestController extends Controller { /** * Write Your Code.. * * @return string */ public function index() { $product = Product::find(1); dd(url("/product/{$product->id}")); } }
Output:
"http://localhost:8000/product/1"
Get Current URL:
If no path is provided to the address helper, a Illuminate\Routing\UrlGenerator instance is came back, enabling you to access info concerning this 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();
So,you can generate of those ways might also be accessed via the URLfacade:
use Illuminate\Support\Facades\URL; echo URL::current();
I hope it will assist you…