laravel-localization icon indicating copy to clipboard operation
laravel-localization copied to clipboard

Laravel API routers got 404

Open beshoo opened this issue 1 year ago • 5 comments

  • Version of Laravel : 9.X
  • Version of the Laravel-localization package
  • Which middleware is used in Route::groups :
Route::group(['prefix' => LaravelLocalization::setLocale(),
              'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]], function()
{
  • Copy of the config file ( or at least setting of supportedLocales, useAcceptLanguageHeader and hideDefaultLocaleInURL).
 'supportedLocales' => [
   
        'en'          => ['name' => 'English',                'script' => 'Latn', 'native' => 'English', 'regional' => 'en_GB'],
        'ar'          => ['name' => 'Arabic',                 'script' => 'Arab', 'native' => 'العربية', 'regional' => 'ar_AE'],

    ]

    // If `hideDefaultLocaleInURL` is true, then a url without locale
    // is identical with the same url with default locale.
    // For example, if `en` is default locale, then `/en/about` and `/about`
    // would be identical.
    //
    // If in addition the middleware `LaravelLocalizationRedirectFilter` is active, then
    // every url with default locale is redirected to url without locale.
    // For example, `/en/about` would be redirected to `/about`.
    // It is recommended to use `hideDefaultLocaleInURL` only in
    // combination with the middleware `LaravelLocalizationRedirectFilter`
    // to avoid duplicate content (SEO).
    //
    // If `useAcceptLanguageHeader` is true, then the first time
    // the locale will be determined from browser and redirect to that language.
    // After that, `hideDefaultLocaleInURL` behaves as usual.
    'hideDefaultLocaleInURL' => false,

    // If you want to display the locales in particular order in the language selector you should write the order here.
    //CAUTION: Please consider using the appropriate locale code otherwise it will not work
    //Example: 'localesOrder' => ['es','en'],
    'localesOrder' => [],

    //  If you want to use custom lang url segments like 'at' instead of 'de-AT', you can use the mapping to tallow the LanguageNegotiator to assign the descired locales based on HTTP Accept Language Header. For example you want ot use 'at', so map HTTP Accept Language Header 'de-AT' to 'at' (['de-AT' => 'at']).
    'localesMapping' => [],

    // Locale suffix for LC_TIME and LC_MONETARY
    // Defaults to most common ".UTF-8". Set to blank on Windows systems, change to ".utf8" on CentOS and similar.
    'utf8suffix' => env('LARAVELLOCALIZATION_UTF8SUFFIX', '.UTF-8'),

    // URLs which should not be processed, e.g. '/nova', '/nova/*', '/nova-api/*' or specific application URLs
    // Defaults to []
    'urlsIgnored' => ['/skipped'],

    'httpMethodsIgnored' => ['POST', 'PUT', 'PATCH', 'DELETE'],

My Router api.php


Route::group(['prefix' => LaravelLocalization::setLocale(),
              'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]], function()
{
        Route::get('/cv/{cv_slug}', [CvsController::class, 'ViewCv']);
});

I opened http://127.0.0.1/cv/api/22333 it redirects me to http://127.0.0.1/cv/en/api/22333 with Router not found

I checked https://github.com/mcamara/laravel-localization/issues/382 and https://github.com/mcamara/laravel-localization/issues/482

and I can not make it works!

beshoo avatar Mar 19 '23 11:03 beshoo

I have exactly the same issue

ghost avatar Mar 19 '23 13:03 ghost

I don't know if this is the best solution but it is working my case. You should add exception something like this:

'urlsIgnored' => ['/api/*'],

config/laravellocalization.php

GergoKormoczy avatar Mar 29 '23 15:03 GergoKormoczy

I already set that.... This plugin is not working.....

On Wed, Mar 29, 2023, 5:17 PM Körmöczy Gergő @.***> wrote:

I don't know if this is the best solution but it is working my case. You should add exception something like this:

'urlsIgnored' => ['/api/*'],

config/laravellocalization.php

— Reply to this email directly, view it on GitHub https://github.com/mcamara/laravel-localization/issues/862#issuecomment-1488826834, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLT23KSXQYJLH7AFDYOY3W6RHAXANCNFSM6AAAAAAWABSUKM . You are receiving this because you authored the thread.Message ID: @.***>

beshoo avatar Mar 29 '23 15:03 beshoo

Then you should run after of course.

php artisan optimize:clear
php artisan route:trans:clear

GergoKormoczy avatar Mar 29 '23 15:03 GergoKormoczy

add ["Accept": "application/json"] to header of the request

fahadapps79 avatar Jul 17 '23 16:07 fahadapps79