laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.22k stars 10.9k forks source link

Different variable name on the route than what was defined. #50370

Closed crazynds closed 6 months ago

crazynds commented 6 months ago

Laravel Version

10.46

PHP Version

8.3.2

Database Driver & Version

PGSql 16

Description

I have the following code that generates the following list of routes: image

The bug is that the formData variable is passed as formDatum instead of the defined name which is formData. I didn't understand why this happens. This is the only one execption i found in my code, all other variables are defined as the same i passed in the apiResource.

Steps To Reproduce

Create an api resource with the parameter formData.

Route::apiResource('formData', FormDataController::class);
rodrigopedra commented 6 months ago

On resource routes, placeholders are converted to their singular form. For example, Route::resource('users') will generate user placeholders.

This is by design, and it is expected behavior. Although not much used, the singular form of "data" is "datum".

You can override this behavior by naming resource parameters, as it is described in the docs:

https://laravel.com/docs/10.x/controllers#restful-naming-resource-route-parameters

Which is a good read before opening issues to double-check the framework's features.

Another tip: don't use code screenshots.

They are awful to read from a mobile, they don't allow easy copy and paste to help debugging, and when one's theme (light/dark) doesn't match your preferred theme, they are even worse to read and understand.

On the bottom of GitHub's textarea, there is a reference saying: "Markdown is supported". That reference is also a link where you can learn how to format code properly and help whoever is willing to help you.

Also, I would consider this note from the docs before posting new issues:

https://laravel.com/docs/10.x/contributions#support-questions

Remember, Laravel is provided for free, mostly by developers contributing in their spare time. And I can guarantee you will be very welcomed on any of the support channels listed on the linked above.

Have a nice day =)