In this laravel 9 blade route with parameter tutorial, I will show you how to define a name route in laravel and call it from a blade file. We can use url()
to create an action link. But in this example, I will show you how to use the route in the blade with the parameter.
Let's assume this is our route:
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/user/{id}', function ($id) {
return $id;
})->name('user');
Now in your blade file, call it like:
resources/views/any_view.blade.php
<a href="{{route('user',$user->id)}}">Button</a>
Laravel blade route with multiple parameters
We can define multiple parameters in the route also. Assume this is our laravel blade route with multiple parameters:
routes/web.php
<?php
Route::get('/details/{id}/{id1}/{id2}', [TestController::class,'index']);
Now we can generate this route in blade like:
resources/views/any_view.blade.php
<a href='{{url("/details/{$var->id}/{$var->id1}/{$var->id2}")}}'>Details</a>
Now use this in your controller like:
<?php
public function index($id, $id1,$id2)
{
//
}
Read also: Laravel 9 Route Model Binding Example
Hope it can help you.