Quickly inspect the database and its tables in Laravel
It’s sometimes convenient if you can quickly glance over the database your Laravel application is using and its tables. This is especially useful when you’re working on a legacy project and you’re not sure about the database structure.
While you can do this in your favorite database management tool like Sequel Pro or TablePlus, it’s not always convenient to open up the tool and connect to the database.
But Laravel is all about convenience, right? So, there’s a way to quickly inspect the database and its tables right from the command line.
The db:show
command
The db:show
artisan command allows you to check quick stats about your database like name, host, port, username, number of tables, etc.
But the most useful thing about this command is that it also shows the number of connections that are currently open to the database. This is especially useful when you’re using a database service like Amazon RDS where you have a limit on the number of connections you can open to the database.
Here’s what the output of the command looks like.
The db:table
command
The db:table
artisan command allows you to quickly inspect the table structure of the database. It shows the table name, columns, number of columns, indexes, foreign keys, and the size of the table in bytes. All in a nice and readable format.
Here’s what the output of the command looks like.
Like this article?
Buy me a coffee👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.