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

What is the naming convention for routes with multiple words #89

Open
glupeksha opened this issue Oct 13, 2020 · 9 comments
Open

What is the naming convention for routes with multiple words #89

glupeksha opened this issue Oct 13, 2020 · 9 comments

Comments

@glupeksha
Copy link

is it Route::resource('master-products','MasterProductController') or Route::resource('masterProducts','MasterProductController')?

@Tpojka
Copy link

Tpojka commented Oct 13, 2020

dashes are fine convention for 'all lower cases' in url string. You can combine dashes and slashes to separate those words by their nature. For example, if you have resource controller and want to add additional route

Route::post('product-details/fetch', 'ProductDetailController@fetch')->name('product_details.fetch');
Route::resource('product-details', 'ProductDetailController');

This way you are following convention of already meant resource routes.

@alexeymezenin
Copy link
Owner

@upeksha1996 go with master-products. https://restfulapi.net/resource-naming/

@glupeksha
Copy link
Author

glupeksha commented Oct 25, 2020

Thank you so much for replies.. Can you also please let me know whether there is a naming convention for view folders? whether the respective folder for the MasterProductController is better to be masterProducts, master-products, master_products?

@Tpojka
Copy link

Tpojka commented Oct 25, 2020

I use underscored variant with addition that it is singular in my case.
So MasterProductController relates with views/master_product directory.

@alexeymezenin
Copy link
Owner

I guess both underscored and camelCase are ok since you can select view names by using double-click in most IDEs.

@glupeksha
Copy link
Author

glupeksha commented Oct 30, 2020

In the laravel documentation, I found out kebab case also.

Route::get('/forgot-password', function () {
    return view('auth.forgot-password');
})->middleware(['guest'])->name('password.request');

@Tpojka
Copy link

Tpojka commented Nov 2, 2020

In the laravel documentation, I found out kebab case also.

Route::get('/forgot-password', function () {
    return view('auth.forgot-password');
})->middleware(['guest'])->name('password.request');

I like to use underscored formations in PHP because it cut off technical debt if in future I have to name variables by it (directory name in this case). Same for PHP, JS or DB (MySQL that I use) having variables can be with underscores but can't with dash. This way I just remove unnecessary limitation. Consider you want for some reason to extend DB and you find yourself in need to create table by concrete directory (these are hypothetical presumptions). It is good to have some string in name that you can easily manage to create variable name from it or to have well consistency between names. This can be broad thinking and it is actually the same for PHP: whether it is - whether _ but for developer's future use it's easier to be _ imho.

@glupeksha
Copy link
Author

@alexeymezenin what do you think?

@alexeymezenin
Copy link
Owner

@upeksha1996 I don't think there is a convention. I saw a lot of different name styles for views in real-life projects and packages.

mb-dir referenced this issue in pasierbpiotr/TransportPlatform Jun 5, 2023
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

No branches or pull requests

3 participants