codezero-be / laravel-localized-routes

⭐️ A convenient way to set up and use localized routes in a Laravel app.
MIT License
505 stars 46 forks source link

Route not defined. #63

Closed Dezmonter closed 2 years ago

Dezmonter commented 2 years ago

I do the entire installation according to the instructions, as a result, when going to any page, an error Route [uk.route_name] not defined. what could be wrong?

ivanvermeyen commented 2 years ago

Hello,

Can you give some more context?

Dezmonter commented 2 years ago

a href="{{ route('web.article.show', $article->slug) }}"

Route::localized(function () {
        Route::get('/articles', [ArticleController::class, 'index'])->name('articles');
        Route::get('/article/{slug}', [ArticleController::class, 'show'])->name('article.show');
        Route::get('/articles/{slug}', [ArticleCategoryController::class, 'show'])->name('article_category.show');
});

Error Route [uk.web.article.show] not defined. ...

Article route list:

GET|HEAD ru/article/{slug} ........................................................................................................................ web.ru.article.show GET|HEAD article/{slug} ........................................................................................................................... web.uk.article.show

UPD! The problem is that I am using RouteServiceProvider to the group web - name.

    public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::middleware('web')
                ->name('web.')
                ->group(base_path('routes/web.php'));
        });
    }

if you remove (->name('web.')) and register manually in each route then it works, but I would like to register name in RouteServiceProvider...

ivanvermeyen commented 2 years ago

If you add the name in the RouteServiceProvider, it's going to be top level... I don't think there is anything we can do about that...