Laravel: New DB Commands

Laravel: New DB Commands

Following last week's release which focused on Artisan, this week's Laravel v9.24 release introduces three new database commands we think you will love.

Artisan "db:show" Command

The "db:show" command

This new command gives you an overview of your database as a whole. When running the command you will see a summary of the database, including its type, connection details, number of open connections, and more.

Artisan "db:table" Command

The "db:table" command

A few weeks ago, Laravel introduced a model:show command that allows you to get a quick overview of an Eloquent model. While this command is helpful, sometimes you may want to inspect the underlying database table instead.

The new db:table command allows you to get a quick, valuable overview of an individual database table used by your application, including its size and number of rows. In addition, this command provdies a breakdown of every column along with its attributes and data type. Of course, all table indexes and foreign keys are summarized as well.

Artisan "db:monitor" Command

The "db:monitor" command

Much like the queue:monitor command, the new db:monitor command allows you to quickly see the number of open connections to your database, which is one indicator of the load it is currently under.

In addition, you may pass the --max option to the command, which will dispatch a DatabaseBusy event when the number of connections is greater than the --max count that was specified. If no --max option is provided, the DatabaseBusy event will not be dispatched.

Keep reading

General April 4, 2024

Encryption and the In-between

Last year, we introduced a simple but surprisingly useful feature to Laravel Forge: the ability to add notes to servers. While checking the uptake of this feature, we noticed that customers were often storing sensitive data in the field. We hadn’t designed notes to store sensitive information, so we found ourselves in a situation where we now needed to encrypt existing unencrypted data, while also allowing for new data to be inserted as encrypted data - at the same time, the dashboard needed to be able to show the notes correctly whether they had been encrypted or not. Our migration process looked like this: 1. Run a command that encrypts all existing unencrypted server notes. 2. Update our model to cast the `notes` field, encrypting or decrypting as required. To do this, we leaned on [Laravel’s custom casts](https://laravel.com/docs/11.x/eloquent-mutators#custom-casts) feature to handle this “sometimes encrypted” data. We created a new cast `SometimesEncrypted` that allowed us to gracefully decrypt the encrypted notes, or simply return the plaintext version which may have been available during the migration: ```php

James Brooks

Stay connected with the latest Laravel news