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

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