Home > OS >  Get Laravel route with optional parameter
Get Laravel route with optional parameter

Time:03-17

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.

CodePudding user response:

The parameters should be in an array like:

echo route('myroute', ['var1', 'var2']);
  • Related