twill icon indicating copy to clipboard operation
twill copied to clipboard

[4.x] Prefix internal Twill users module routes to prevent conflicts with another User model

Open Tofandel opened this issue 1 year ago • 1 comments

Given the following twill route

\Illuminate\Support\Facades\Route::prefix('app')->group(function () {
    TwillRoutes::module('users');
});

And the following navigation

        TwillNavigation::addLink(
            NavigationLink::make()
                ->title('Users')
                ->forModule('users')
                ->setChildren([
                    NavigationLink::make()->title('Professions')->forModule('userProfessions'),
                ])
        )

Until I run php artisan route:cache the link in the menu is correct After the cache, the link goes to /users without the group prefix

image image

Setting ->forModule('app.users') (the route being listed as twill.app.users.index results in image

Which is not a descriptive error message

Setting ->forRoute('twill.app.users.index') gives the desired result but it's weird to have the behavior differ between route cached or not (routes are only cached when staging so it's not caught straight away)

Tofandel avatar May 10 '24 12:05 Tofandel

Very likely due to $this->addToRouteRegistry($slug, $customRoutePrefix); which is a side effect in the route registration

My biggest problem is the fact that the twill users management is registered as the users module which is very easy to conflict with user being a very common model name, maybe we should have the default user route under a prefix to avoid those issues (but would have to be v4 likely or maybe in v3 it could be enabled with an option)

Tofandel avatar May 10 '24 13:05 Tofandel