Published Mar 03, 2025. Written by Kurtis Holsapple.
I was recently browsing Reddit and a lot of people were talking about what they would change in Laravel if they could have their wishes granted. Surprisingly, many people were annoyed at how hard it is to get the information about a model. Some people were talking about having their DB open to just look at the columns, others were talking about adding doc blocks and other stuff to try and get the info into their IDE.
It seemed to me that many people possibly didn't know about the awesome artisan command php artisan model:show ModelName
. This dumps a ton of info out into your terminal about that model, including columns, dynamic attributes, attribute casting, relations, database table name, etc etc etc. It's a fantastic reference! I pointed this out, and got a reply that one person thought it was cool, but would never remember that was available.
I have a quick keyboard shortcut to show me this in the integrated terminal, and thought it would be worthwile to share it with the world. Here at OFC, we all use VS Code as our default editor, so that we can keep our tooling in sync. We're a fully remote team, so making sure we all work together is crucial. So, if you're also using VS Code, and do Laravel development, feel free to add this super tiny keyboard shortcut to your configuration. Here you go!
keybindings.json
file{
"key": "ctrl+m ctrl+m",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "php artisan model:show '${fileBasenameNoExtension}'\u000D"
}
}
Let's break this down!
First, the keybinding is ctrl+m ctrl+m
which means that if you hold down the ctrl key, then press M, lift your finger up, then press M again, this key binding will fire (M for model).
Next, the command is workbench.action.terminal.sendSequence
which means we are going to send a bunch of keys to the integrated terminal. The keys that we are sending are defined in the text
section of the args
: php artisan model:show '${fileBasenameNoExtension}'\u000D
. We start with the default artisan command php artisan model:show
followed by the currently open filename without the path or extension (which should match your classname, thanks PSR-4!). And finally, we send the "Return key" with this lovely little blob: \u000D
.
We all use Linux or Mac OS for our local dev machines, so if you're on windows, you might have to change some of this to make it work. We all also have PHP installed and it's in our path, so even if we are are running Herd or Sail or some other docker config for the laravel project, we have access to the php runtime in our terminal.
Yes, this will not work if you have a non-model file focused in your editor. You'll probably see some error like:
php artisan model:show 'AuthenticatedSessionController'
ERROR Target class [App\Models\AuthenticatedSessionController] does not exist.
This makes sense, because I'm looking at a controller (AuthenticatedSessionController.php to be exact), and I'm trying to get info for a Model. I'm not about to try and make this keyboard shortcut more complex, when the error is pretty obvious that I'm just not looking at a model.
That covers it, thanks for reading!