Get "PHP 8 in a Nuthshell" (Soon includes PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

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.

db:show command

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.

db:table command

Learn the fundamentals of PHP 8 (including 8.1, 8.2, and 8.3), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

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.

Comments?