We’ve seen how to create static routes with Laravel.
Sometimes you want your routes to be dynamic.
This will be especially useful with databases, but let’s do an example without first.
In routes/web.php add an entry like this:
Route::get('test/{name}', function($name) {
return view('test', ['name' => $name]);
});
and in resources/views/test.blade.php write this code:
@if (isset($name))
Hello {{$name}}
@else
Test
@endif
Now if you navigate with your browser to the /test/flavio route, “flavio” is the $name parameter in the route, which is passed to the view, so you can print it in the Blade template:

Change the route parameter, the name in the HTML changes:
