jeudi 1 février 2018

Laravel 5.5 locale as prefix in url

At the moment I have in my routes/web.php the following:

Route::group( [ 'prefix' => '{locale?}', 'middleware' =>\App\Http\Middleware\Locale::class ], function (\Illuminate\Routing\Router $router) {

    Route::get( '/', 'LandingController@index' )->name( 'home' );
    Route::get( '/hero/create', 'HeroController@create' )->name( 'hero.create' );
} );

This doesn't really work as it should be.

What I want is to have an url like this:

/create/hero    # should work with the default locale
/fr/create/hero # should use the french locale
/nl/create/hero # should use dutch locale
/               # should work with the default locale
/fr             # should use the french locale
/nl             # should use dutch locale

So I want the locale parameter optional at the beginning of the url. So far what I've managed to achieve is only to get the urls working when specifying the locale myself. I always get a not found message when I don't manually specify the locale.

How can I set a default value for the locale prefix in my url?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2Fyg8lG
via IFTTT

Aucun commentaire:

Enregistrer un commentaire