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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners