php - Laravel 5.3 How to avoid locale before prefix in api routes in multilanguage app? -


i've built multilanguage app in laravel 5.3 , have bunch of api routes return me resources url http://app-domain.com/api/resource when i'm on default language.

the problem presents when i'm not in default language. when app tries call api sends request http://app-domain.com/locale/api/resource returns nothing since it's not correct path.

my implementation simple, basic routing in routes/api.php

route::group([     'prefix' => 'api'   ],function() {     route::get('resource', 'apicontroller@getresource')->name('get-resource'); }); 

then i'm using jquery ajax object call it

$.get( "api/resource", function( data ) {   //run somecode }); 

how can address problem , have api routes resolving correctly no matter language? there params can set in routes prevent this? i've been looking in documentation found nothing relevant.

p.s.: i'm using mcmanamara laravel localization

imho setting locale better if use query-string: i.e.:

http://app-domain.com/api/resource?locale=en

for two, valid, reasons:

1) locale in querystring non existing, can fallback default locale.

2) having locale parameter in route conflict other routes parameters generating lot of confusion


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -