dimanche 19 avril 2020

Laravel treats optional url parameter as obligatory

I am trying to make several url have optional prefix. Now I've added just 2 urls to that group: base url '/' and test url. For base url everything works fine. But when I try to reach test url without prefix I get 404. Where could be the problem?

Here is a part of my routes/web.php

Route::group([
    'prefix' => '{lang?}',
    'where' => ['lang' => '[a-z]{2}'],
    'middleware' => 'localization'
], function () {
    Route::get('/', function () {
        return view('welcome');
    });

    Route::get('/test/me/please', function () {
        return 'Bla Bla Bla';
    });
});

And here is the output of php artisan route:list:

+--------+----------+------------------------+------+---------+------------------+
| Domain | Method   | URI                    | Name | Action  | Middleware       |
+--------+----------+------------------------+------+---------+------------------+
|        | GET|HEAD | api/user               |      | Closure | api,auth:api     |
|        | GET|HEAD | {lang?}                |      | Closure | web,localization |
|        | GET|HEAD | {lang?}/test/me/please |      | Closure | web,localization |
+--------+----------+------------------------+------+---------+------------------+


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire