Source: www.amitmerchant.com

Invisible MySQL columns in Laravel 8.x

Category: Laravel, PHP, MySQL, javascript

Let’s imagine a scenario where you have a MySQL table called users and there’s a column called secret which holds a secret token for the associated users. How would you prevent this column from not being there when someone queries everything (i.e SELECT * query) from this table? Well, one way is to explicitly specify each column in the SELECT query except the secret column. Or if you’re using MySQL 8.0.23 and onwards, you could define the secret column as “invisible”.

CREATE TABLE users ( secret TINYTEXT INVISIBLE ) ENGINE = InnoDB; Or when you’re altering the table.
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