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

Provide a way of customizing/disabling the default routes #44

Closed
m1guelpf opened this issue Sep 4, 2020 · 2 comments
Closed

Provide a way of customizing/disabling the default routes #44

m1guelpf opened this issue Sep 4, 2020 · 2 comments

Comments

@m1guelpf
Copy link
Contributor

m1guelpf commented Sep 4, 2020

There's currently no way to prevent the default routes from being registered. This isn't great when you want to have more control over the paths of each route. It would be great to be able to call Jetstream::ignoreRoutes() and to provide the option of exporting the default routes.

Current Workaround

Here's what I'm currently doing to overcome this. Warning, this code is extremely cursed and should probably not be used in production 😅

const REWRITE_PATHS = [
    'user/profile' => 'user/account',
];

if ($this->app->routesAreCached()) return;

$router = $this->app->make(Router::class);
$collection = new RouteCollection;

collect($router->getRoutes()->getIterator())->map(function ($route) use ($paths) {
    if (array_key_exists($route->uri, REWRITE_PATHS)) {
        $route->uri = REWRITE_PATHS[$route->uri];
    }

    return $route;
})->map(fn ($route) => $collection->add($route));

$router->setRoutes($collection);

Better ideas are welcome

@rajakhoury
Copy link

I was wondering the same but to be honest I don't think this is the right way.
You could disable the auto-discovery for this package and do it manually. Add this to your composer.json

"extra": {
    "laravel": {
        "dont-discover": [
            "laravel/jetstream"
        ]
    }
}

now you need to register your custom routes/views so in App\Providers\JetstreamServiceProvider extend the base Provider and override whatever you need. e.g

class JetstreamServiceProvider extends \Laravel\Jetstream\JetstreamServiceProvider
{
    public function boot()
    {
        // See required parent methods
        // e.g $this->configureComponents()

        // Register the custom routes or move it the RouteServiceProvider or whatever seems logic
        Route::group([
            'namespace' => 'Laravel\Jetstream\Http\Controllers',
            'domain' => config('jetstream.domain', null),
        ], function () {
            $this->loadRoutesFrom(base_path('routes/jetstream.php'));
        });

        // $this->configurePermissions();
    }

    //
}

I am also intrested in knowing if this is how you're supposed to do it.

@driesvints
Copy link
Member

Yeah think Taylor will accept a PR for that. Feel free to PR 👍

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