You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
Describe the bug
When creating a relationship on a table that references other records of the same table, the routes generated use the entity name rather than the relationship name. For instance, in the application I'm currently building, I have a "pests" table for defining various insects. Some insects are predators, some insects are prey, and some insects are both. When creating a new insect, the following LogicException appears: Route pattern "/api/pests/{pest}/pests/{pest}" cannot reference variable name "pest" more than once.
There is also only a single API controller created for handling the requests: PestPestsController, rather than 2 controllers: PestPredatorsController and PestPreyController.
My example is fairly specific, however I could see this being an issue with more common scenarios such as creating taxonomies with parent/child relationships.
To Reproduce
Steps to reproduce the behavior:
Create an entity called "Pest"
Add a "belongsToMany" relationship, using the following settings:
a. Relationship Name: "predators"
b. Pivot Table Name: "predator_prey"
c. Local Model Key Name: "predator_id"
d. Joined Model Key Name: "prey_id"
Once saved, an additional "belongsToMany" relationship is automatically created named "pests", edit this relationship as follows:
First input: "prey"
Second input: "prey_id"
Third input: "predator_id"
Generate the code, run migrations, and open in the browser.
Create a new pest. Once saved, an error will appear: Route pattern "/api/pests/{pest}/pests/{pest}" cannot reference variable name "pest" more than once.
Expected behavior
For relationships, I believe the route keys should use the relationship name rather than the entity name, and add the proper binding to the boot method of the RouteServiceProvider if the relationship name is customized as shown in the docs. E.g.:
Describe the bug
When creating a relationship on a table that references other records of the same table, the routes generated use the entity name rather than the relationship name. For instance, in the application I'm currently building, I have a "pests" table for defining various insects. Some insects are predators, some insects are prey, and some insects are both. When creating a new insect, the following
LogicException
appears:Route pattern "/api/pests/{pest}/pests/{pest}" cannot reference variable name "pest" more than once.
There is also only a single API controller created for handling the requests:
PestPestsController
, rather than 2 controllers:PestPredatorsController
andPestPreyController
.My example is fairly specific, however I could see this being an issue with more common scenarios such as creating taxonomies with parent/child relationships.
To Reproduce
Steps to reproduce the behavior:
Route pattern "/api/pests/{pest}/pests/{pest}" cannot reference variable name "pest" more than once.
Expected behavior
For relationships, I believe the route keys should use the relationship name rather than the entity name, and add the proper binding to the boot method of the RouteServiceProvider if the relationship name is customized as shown in the docs. E.g.:
https://laravel.com/docs/10.x/routing#explicit-binding
The routes should be generated as follows:
Finally, there should be 2 controllers generated:
PestPredatorsController
andPestPreyController
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: