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

Add RoutedBy Eloquent model attribute #54468

Closed

Conversation

bakerkretzmar
Copy link
Contributor

Adds a RoutedBy attribute to set a custom route key name on a model:

#[RoutedBy('slug')]
class Post extends Model
{
    //
}

Same idea as #49843, #53122, and #54065. This attribute provides a more compact way to set a custom routing key, instead of overriding the getRouteKeyName method.

Fully backwards-compatible and optional, getRouteKeyName continues to work exactly as before and takes precedence over this attribute.

@shaedrich
Copy link
Contributor

@bakerkretzmar Did you consider going with #[UseRouteKey()] instead to not have this confused with Symfony's #[Route] attribute?

@bakerkretzmar
Copy link
Contributor Author

@shaedrich that name could work too and I'll defer to the Laravel team of course, just tried to make it consistent with the existing CollectedBy and ObservedBy. I doubt there would be confusion with that specific attribute though since it isn't part of Laravel.

@shaedrich
Copy link
Contributor

Yeah well, Symfony is part of Laravel and we had a similar discussion in #54065.

@henzeb
Copy link
Contributor

henzeb commented Feb 5, 2025

just out of curiosity, how is RoutedBy going to be confused with Route?

@shaedrich
Copy link
Contributor

@henzeb I had to look up that it returns the routeKey—this isn't explicitly conveyed by the attribute naming

@taylorotwell
Copy link
Member

I think we need to have a broader thought process about why and when we use attributes as a framework instead of piece meal adding them in various places.

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.

4 participants