laravel / jetstream

Tailwind scaffolding for the Laravel framework.
https://jetstream.laravel.com
MIT License
3.98k stars 822 forks source link

User route config #572

Closed c-fitzmaurice closed 3 years ago

c-fitzmaurice commented 3 years ago

In the Jetstream config file there is no way to adjust the routes, like the Fortify config file. It would be great if we could customize the user profile URLs. I would like to use my User Model's username field as a slug for the user profile:

from

/user/profile

to

/{username}/profile

IIf this is something that would be considered useful I could maybe start looking into a PR.

joelbutcher commented 3 years ago

Firstly, Fortify allows you to specify a route prefix to all routes. So whilst I agree route customisation would be nice, I'm not sure your example will work.

Let's take your example:

/{username}/profile

In order to make this possible, you would need to always assume that the username wildcard will resolve for the current user. I'm personally not a fan of this as I've always had the philosophy that assumptions are bad in programming. This would also mean that routes such as /foo/profile would resolve and allow you to view the your profile, given the current controller logic. I suspect this isn't the effect you're looking for?

One alternative is to change the logic used to resolve the user and use the username route wildcard. The complexity here is that a UserPolicy will need to be implemented as well as user.view files, so that when visiting other users profiles, you do not end up modifying (or worse, deleting) that profile. I suspect this kind of change is unlikely to get Taylor's approval due to the maintenance burden associated with the complexity.

The final alternative is to publish the routes file using

php artisan vendor:publish --provider="Laravel\Jetstream\JetstreamServiceProvider" --tag=jetstream-routes

Then modifying your RouteServiceProvider to load the routes from the published routes/jetstream.php file.

driesvints commented 3 years ago

@c-fitzmaurice Please see the answer above.

@joelbutcher thanks!

c-fitzmaurice commented 3 years ago

Thanks @joelbutcher !