laravel-best-practices icon indicating copy to clipboard operation
laravel-best-practices copied to clipboard

URI naming convertion?

Open sweatyc opened this issue 6 years ago • 5 comments

E.g.: $router->get('/users/forgot_password', 'UserController@forgotPassword'); or $router->get('/users/forgot-password', 'UserController@forgotPassword'); or $router->get('/users/forgotPassword', 'UserController@forgotPassword');

there's no clue in Resource Controllers doc, but I guess forgot-password seems to be the way to go.

sweatyc avatar Jan 14 '19 04:01 sweatyc

E.g.: $router->get('/users/forgot_password', 'UserController@forgotPassword'); or $router->get('/users/forgot-password', 'UserController@forgotPassword'); or $router->get('/users/forgotPassword', 'UserController@forgotPassword');

there's no clue in Resource Controllers doc, but I guess forgot-password seems to be the way to go.

$router->get('/users/forgot-password', 'UserController@forgotPassword');

URL часто регистронезависимый

case insensitive + str_slug str_slug(forgot_password) -> forgot-password

dmitrach avatar Jan 16 '19 17:01 dmitrach

But why "named route" uses snake_case ?

image

anandiamy avatar Jul 09 '19 06:07 anandiamy

For named routes is something that is not exposed to the user, and I think we mainly want snake case there because is easier to copy/paste(?), URIs are and these seems to be easier to read for most users I think. Hyphens are the standard across the web for URIs.

Is a good point though might be easier to remember, in exchange of say not being able to double click to select and copy/paste it.

@anandiamy

poncianodiego avatar Jul 09 '19 06:07 poncianodiego

@anandiamy

I see several reasons:

  1. In a text editor, to select a whole phrase, you need to double-click the mouse. The phrase should be separated by the symbol "_", and not "-" (depending on the settings).
  2. Most often use short names with one verb or noun.

dmitrach avatar Jul 09 '19 07:07 dmitrach

@anandiamy URLs are not related to Laravel, so you can use any of them. Personally, I prefer to use -.

As for routes and similar Laravel related stuff, I prefer to use _ for the reasons @poncianodiego and @dios-oleg were talking about. Some developers don't like it and currently, there is voting here https://github.com/alexeymezenin/laravel-best-practices/pull/24

alexeymezenin avatar Jul 09 '19 08:07 alexeymezenin

I've updated the misleading name Named Route to Route name to avoid similar confusion.

spekulatius avatar Oct 19 '22 12:10 spekulatius