I was wondering if it’s possible to get the full url/path in Laravel with a optional parameter in it.
In web.php I have this:
Route::get('/blabla/{var1}/blabla/{var2?}', [Controller::class, 'function'])->name('myroute');
And want to get the full url/path with this:
echo route('myroute', 'var1', 'var2');
But only ‘var1’ appears. How come? In the manual there are no examples.
Advertisement
Answer
The parameters should be in an array like:
echo route('myroute', ['var1', 'var2']);