Hi dev,
Today, i show you laravel 10 generate dynamic URL. This article will give you simple laravel 10 generate dynamic URL. you will laravel 10 generate dynamic URL. In this article, we will implement a laravel 10 generate dynamic URL. The generated URL will automatically use the scheme (HTTP or HTTPS) and host from the current request.
So, let’s follow few steps to create example of laravel 10 generate dynamic URL.
Laravel 10 Install
Follow This Command And Install Laravel
composer create-project laravel/laravel blog
Solution:
<?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:
// 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();
generate these methods that may also be accessed via the URL facade:
use Illuminate\Support\Facades\URL; echo URL::current();
I hope it will assist you…