Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel API routers got 404 #862

Open
beshoo opened this issue Mar 19, 2023 · 5 comments
Open

Laravel API routers got 404 #862

beshoo opened this issue Mar 19, 2023 · 5 comments

Comments

@beshoo
Copy link

beshoo commented Mar 19, 2023

  • 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
#382
and
#482

and I can not make it works!

@ghost
Copy link

ghost commented Mar 19, 2023

I have exactly the same issue

@GergoKormoczy
Copy link

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

@beshoo
Copy link
Author

beshoo commented Mar 29, 2023 via email

@GergoKormoczy
Copy link

Then you should run after of course.

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

@fahadapps79
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants