-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[9.x] Artisan model:show
command
#43156
Conversation
That's awesome to have! I see myself all the time running to the database to check some model information, especially when you jump from project to project. Great job! 😃 |
Looks great! It would be useful if it also shows indexes that each column has (unique, primary, foreign key). I'm working on a big project where some columns are missing important indexes (sometimes even primary keys). This command could make it easier to find those missing indexes. Maybe the command could even display a yellow warning banner:
|
I suggest |
@jessarcher I've put this pull request on draft, so you can review my suggestion to the layout: #43170. |
95192b6
to
187603c
Compare
Very nice work! 👍 I think it could be worthwile to refactor the column/relation finding logic to it’s own class that the command would use. This way, others can also make use of the gathered information. It could also be cool to somehow let a model append custom information to the output. |
68b5e6d
to
e1a8ce1
Compare
Co-authored-by: Enzo Innocenzi <[email protected]>
e1a8ce1
to
262e65c
Compare
262e65c
to
7256908
Compare
A suggestion , add this info as doc inside each model (like laravel-ide-helper does). |
Great work! @jessarcher 👏🏻 |
This looks awesome, thank you @jessarcher! |
This PR introduces a new
model:show
command that displays information for a model. It combines information from the database alongside information from Eloquent to give you a complete overview of your model.This command is especially useful as your application grows and you have multiple migrations for a single table, with all sorts of casts, accessors, etc.
Not only does it show columns from the database, but it also displays "virtual" attributes - I.e. accessors/attributes that don't have a matching column in the database (See
first_name
andlast_name
in the screenshot).Note that the column type information depends on the database. For example, PostgreSQL doesn't have unsigned information and SQLite doesn't have bigints or column lengths.
It also conveniently displays model relationships, including those defined in traits.
There is a
--verbose
(or-v
) flag that will also show any default values. It first checks for any defaults specified in the$attributes
key of your model before falling back to any default specified in the database.There is also a handy
--json
flag that will return everything as JSON, which I could imagine useful for tools like https://github.com/barryvdh/laravel-ide-helper, https://github.com/nunomaduro/larastan, and https://laravelshift.com.JSON Example
The results do depend on the current state of the database, so any changes made outside of a migration will be reflected here, but any changes from not-run migrations will not.
I'd also like to acknowledge https://github.com/barryvdh/laravel-ide-helper for some of the logic around finding attributes and relationships, and @nunomaduro for his help with the UI 💅