0

I'm having trouble creating ONE laravel route that has an optional parameter. The following achieves the behaviour I want:

Route::get('/{locale}/donate', 'MyController@index')->name('donation.index');
Route::get('/donate', 'MyController@index')->name('donation.index');

Both the urls /fr/donate and /donate will load the MyController index(). However, when I do this:

Route::get('/{locale?}/donate', 'MyController@index')->name('donation.index');

The /donate will not load the MyController index(). How do I make the locale argument an optional segment in the url?

1

1 Answer 1

-2

In my opinion there is no way to define the parameter as optional. Here are other ways to solve your problem.

First

Create a subdomain for that

Second move your optional parameter to the last. Now your route will look like this

Route::get('/donate/{locale?}', 'MyController@index')->name('donation.index');
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.