Category: Laravel, MySQL

Let’s see how can we use computed columns in our database schema and in what scenarios should we add them to our migrations.

The main difference between the two is virtual is getting computed every time when the user runs the query but it does not take any space, however, the stored takes some space for its data, but it will be updated every time when the row is getting inserted or updated.

Let’s see some SQL, how to create computed columns: As we can see, we can generate columns based on other columns in the row.

Now, let’s take a look at how can we add computed columns to our Laravel migration.

This also means we can easily append these to our models and no need to add computed properties to the models themselves.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners