Laravel-Backpack / Generators

Generate files for Backpack projects
http://backpackforlaravel.com
MIT License
315 stars 64 forks source link

[Improvement] Change CRUD command & route from singular to plural #63

Open tabacitu opened 4 years ago

tabacitu commented 4 years ago

Right now we ask people to run

php artisan backpack:crud tag # use singular, not plural

Which is a little counter-intuitive. Since the db table is plural, I think it'll be easier for people to run the plural name instead. We chose to use the singular because, in the past, the Laravel best practice was to use singular for Resource Routes, and for Controller name. Now the best practice is to have plural for resource route (Route::resource('tags', 'TagController');) but still singular for Controller name. That's why, I think, in addition to changing the command from singular to plural, we should also change the route. So that it's:

-admin/tag
-admin/tag/create
-admin/tag/update
+admin/tags
+admin/tags/create
+admin/tags/update

But this means we need to be super-sure about both the single and plural name, basically asking both from the user. So maybe instead we should do something like this:

php artisan backpack:crud                           # no mandatory parameters

# What's the table in the database?
> tags
     # [ERROR] Did not find table "tags" in the database.
# Confirm or edit your entity name, in plural, in English? (ex: tags, products, users)
> tags
# Confirm or edit your entity name, in singular, in English? (ex: tag, product, user)
> tag
# Found Model "App\Tag" - do you want to use it? (y/n)
#    (N) > Where do you want to generate your new Model?
         > App\Models\Tag
#
# ---------------
# Generated app/Models/Tag.php
# Generated app/Http/Requests/Tag.php
# Generated app/Http/Controllers/Admin/TagCrudController.php
# Added Route::crud('tag', 'TagCrudController'); to routes/backpack/custom.php
# Added sidebar item to resources/views/vendor/backpack/base/inc/sidebar_contents.blade.php
# ---------------
#       Done 
# ---------------

Once you specify the table name (tags) we can offer sensible defaults for the rest of the prompts:

This way, you don't have to remember if it's singular or plural, the command-line prompt tells you exactly what it needs. You just need to remember php artisan backpack:crud - which is super-easy to remember. Possible alias: php artisan make:crud. For backwards-compatibility, we should probably keep the "singular" as an OPTIONAL parameter. Or we could leave php artisan backpack:crud as-is, and create this new command php artisan make:crud which is more powerful. But I see no point in having both, tbh.

To sum up, what I propose we do here:

eduardoarandah commented 4 years ago

Agree! Spanish has some non-regular plural variations

I tend to use singular everywhere (why complicate life?) except from things the user needs to see, like urls

tabacitu commented 4 years ago

Update: I think we've got enough breaking changes as-is. And plenty of people have already installed 4.1 with the singular form. So let's postpone this for 6 months, until Backpack 4.2 - I hope that one will have less breaking changes.

stale[bot] commented 4 years ago

Hi there!

Is this still an issue? No activity in 60 days. I'm going to mark it as stale for now, and close it in 14 days if no further activity occurs. I know you guys are all busy, but if this is important to you please reply or something, so I know not to close it.

Thank you!

-- Justin Case The Backpack Robot

joelmellon commented 4 years ago

@tabacitu "But this means we need to be super-sure about both the single and plural name, basically asking both from the user."

Laravel's Str::plural() works pretty well. Could you just use that?

"we can get the singular by stripping the 's' - tag;" won't always work, but again, Str::plural() should handle these cases just fine (starting with singular). I think this means that you wouldn't have to change the user interface either.

tabacitu commented 3 years ago

Yeah you're right @joelmellon , it works pretty well in English. And class names, models should be in English anyway. So that should work well!

Also note here (TLDR of my comment in https://github.com/Laravel-Backpack/CRUD/pull/3121#issuecomment-709359836) - we should also split the words by dashes! To end up with user-setting not usersetting šŸ˜Œ

stale[bot] commented 3 years ago

Hi there!

Is this still an issue? No activity in 60 days. I'm going to mark it as stale for now, and close it in 14 days if no further activity occurs. I know you guys are all busy, but if this is important to you please reply or something, so I know not to close it.

Thank you!

-- Justin Case The Backpack Robot

joelmellon commented 3 years ago

Also note here (TLDR of my comment in Laravel-Backpack/CRUD#3121 (comment)) - we should also split the words by dashes! To end up with user-setting not usersetting šŸ˜Œ

That's a great idea. Solves the most if not all of the issues here I think.

stale[bot] commented 3 years ago

Hi there!

Is this still an issue? No activity in 60 days. I'm going to mark it as stale for now, and close it in 14 days if no further activity occurs. I know you guys are all busy, but if this is important to you please reply or something, so I know not to close it.

Thank you!

-- Justin Case The Backpack Robot

pxpm commented 3 years ago

bump!

stale[bot] commented 2 years ago

Hi there!

Is this still an issue? No activity in 60 days. I'm going to mark it as stale for now, and close it in 14 days if no further activity occurs. I know you guys are all busy, but if this is important to you please reply or something, so I know not to close it.

Thank you!

-- Justin Case The Backpack Robot

stale[bot] commented 7 months ago

Hi there!

Is this still an issue? No activity in 60 days. I'm going to mark it as stale for now, and close it in 14 days if no further activity occurs. I know you guys are all busy, but if this is important to you please reply or something, so I know not to close it.

Thank you!

-- Justin Case The Backpack Robot

pxpm commented 7 months ago

bump