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 #67

Merged
merged 1 commit into from
Sep 7, 2020
Merged

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

merged 1 commit into from
Sep 7, 2020

Conversation

m1guelpf
Copy link
Contributor

@m1guelpf m1guelpf commented Sep 5, 2020

This PR introduces a way of disabling registration of the default routes like other Laravel packages already allow (Cashier, for example). It also adds an option to publish the routes for the adapter you're currently using to your routes folder.

Resubmission of #54

@MarkIvanowich
Copy link

Now that we can see the changes, I much prefer this solution to my own.

@MarkIvanowich MarkIvanowich mentioned this pull request Sep 5, 2020
src/Jetstream.php Outdated Show resolved Hide resolved
@taylorotwell
Copy link
Member

Do you have a really good reason to do this? I'm trying to understand if this would ever actually be useful.

@m1guelpf
Copy link
Contributor Author

m1guelpf commented Sep 7, 2020

My use-case for this is to have more control over the path each route uses (for my application, I wanted to leave the /profile route for actual profiles and use /account for Jetstream settings, which I don't think will be a super common use-case, but I think giving the option to the user is still a good idea.

@taylorotwell taylorotwell merged commit eae4a8a into laravel:master Sep 7, 2020
@m1guelpf m1guelpf deleted the routes branch September 7, 2020 13:27
@rodrigopedra
Copy link

rodrigopedra commented Sep 8, 2020

Hi @taylorotwell ,

Now that this PR was accepted, can you reconsider the similar PR for Fortify?

PR laravel/fortify#13 by @MarkIvanowich

It basically does the same as this one.

For some projects I work on, customizing the authentication routes is a requirement. Specially when migrating old ones that already use custom routes and have some integration in place with other systems.

Thank you very much.

@yob-yob
Copy link

yob-yob commented Oct 5, 2020

Hi, can I ask how can i use this feature?

How should I override the value of $registersRoutes? is there any good recommendation? like should I do it on AppServiceProvider? or on JetStreamServiceProvider? and how should I do it?

should I just say Laravel\Jetstream\Jetstream::registersRoutes = false; on the boot methods of any of this files?

@m1guelpf
Copy link
Contributor Author

m1guelpf commented Oct 5, 2020

You just need to run Jetstream::ignoreRoutes() on the boot method of your AppServiceProvider.

@yob-yob
Copy link

yob-yob commented Oct 5, 2020

okay, so I guess after that I should be able to insert this code to my JetstreamServiceProvider on the boot method...

Route::group([
            'namespace' => 'App\Http\Controllers\Livewire',
            'domain' => config('jetstream.domain', null),
        ], function () {
            $this->loadRoutesFrom(base_path('routes/jetstream.php'));
        });

making the jetstream route file working...

@rhurling
Copy link

I had to move Jetstream::ignoreRoutes() to the register method of my AppServiceProvider
(since the Laravel\Jetstream\JetstreamServiceProvider::boot method runs before the App\Providers\AppServiceProvider::boot method in the default cached configuration)

], function () {
$this->loadRoutesFrom(__DIR__.'/../routes/'.config('jetstream.stack').'.php');
});
if (Jetstream::$registersRoutes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m1guelpf Could you add a matching method to the Jetstream class and call that here, instead of directly accessing the class property? It would keep the code consistent with the patterns used across this package

@joevallender
Copy link

This is a great option to have. I recently wanted to change the Team(s) vocabulary to Project(s) and this worked perfectly.

I've written up the steps I followed to make the change in a blog post in case it's useful for others
https://aboutweb.dev/blog/change-laravel-jetstream-route-paths/

@mokhosh
Copy link

mokhosh commented Apr 5, 2021

@m1guelpf this doesn't let you customize the routes or disable only some of them, right? All or nothing?

@joevallender
Copy link

@mokhosh You can change whatever you want. Look at the routes file which is published https://github.com/laravel/jetstream/blob/2.x/routes/inertia.php

Once you've completed the necessary steps, you'll have a copy of this (or the Livewire equivalent) file in your project and can edit it however you see fit

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

Successfully merging this pull request may close these issues.

None yet

9 participants