Description
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:
- we already have the name of the entity in plural -
tags
; - we can get the singular by stripping the "s" -
tag
; - we can check the
app
folder for any class that extendsModel
that is either calledTag.php
, or has$table = 'tags';
inside it; to see if the dev already has a Model they might want to use; - we know a good name place for the generated Model would be
App\Models\Tag.php
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:
- make parameter in
php artisan backpack:crud
optional; - prompts to ask for the table name; then ask to confirm both singular and plural form of the entity; and if there's already a Model, ask if they want to use the existing model;
- change CRUD route to use plural form, just like table name:
Route::crud('tags', 'TagCrudController');
Metadata
Metadata
Assignees
Type
Projects
Status